From 6c75098ef3f4013be86c61f1963c2187601f9221 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Mon, 13 Feb 2017 13:05:01 +0300 Subject: [PATCH] Reinstantiate debug adapter earlier To avoid race conditions on app reload, when session dispatches another attach request to adapter (because app worker has sent connected' event) __before__ previous adapter instance was completely disposed we now create new instance of adapter closer to dispatching request, so session would always use new instance. --- src/debugger/nodeDebugWrapper.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/debugger/nodeDebugWrapper.ts b/src/debugger/nodeDebugWrapper.ts index 006766726..efb855187 100644 --- a/src/debugger/nodeDebugWrapper.ts +++ b/src/debugger/nodeDebugWrapper.ts @@ -41,12 +41,8 @@ export function makeSession(debugSessionClass: typeof ChromeDebuggerCorePackage. public sendEvent(event: VSCodeDebugAdapterPackage.Event): void { // Do not send "terminated" events signaling about session's restart to client as it would cause it // to restart adapter's process, while we want to stay alive and don't want to interrupt connection - // to packager. Also in this case we need to reinstantiate the debug adapter, as the current - // implementation of ChromeDebugAdapter doesn't allow us to reattach to another debug target easily. - // As of now it's easier to throw previous instance out and create a new one. + // to packager. if (event.event === "terminated" && event.body && event.body.restart === true) { - // Casting debugAdapter to any to make this compile, as TS doesn't allow instantiating abstract classes - this._debugAdapter = new (debugSessionOpts.adapter)(debugSessionOpts, this); return; } @@ -185,6 +181,10 @@ export function makeSession(debugSessionClass: typeof ChromeDebuggerCorePackage. let attachArguments = Object.assign({}, request.arguments, { port, restart: true, request: "attach" }); let attachRequest = Object.assign({}, request, { command: "attach", arguments: attachArguments }); + // Reinstantiate debug adapter, as the current implementation of ChromeDebugAdapter + // doesn't allow us to reattach to another debug target easily. As of now it's easier + // to throw previous instance out and create a new one. + this._debugAdapter = new (debugSessionOpts.adapter)(debugSessionOpts, this); super.dispatchRequest(attachRequest); });