Skip to content

Commit

Permalink
debug: better disposing of listeners
Browse files Browse the repository at this point in the history
fixes #5091
  • Loading branch information
isidorn committed Apr 13, 2016
1 parent 9261bc5 commit 96c3dbc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/vs/workbench/parts/debug/electron-browser/debugService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService

this.model = new model.Model(this.loadBreakpoints(), this.storageService.getBoolean(DEBUG_BREAKPOINTS_ACTIVATED_KEY, StorageScope.WORKSPACE, true), this.loadFunctionBreakpoints(),
this.loadExceptionBreakpoints(), this.loadWatchExpressions());
this.toDispose.push(this.model);
this.viewModel = new viewmodel.ViewModel();

this.registerListeners(eventService, lifecycleService);
Expand All @@ -136,7 +137,7 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
lifecycleService.onShutdown(this.store, this);
lifecycleService.onShutdown(this.dispose, this);

this.windowService.onBroadcast(this.onBroadcast, this);
this.toDispose.push(this.windowService.onBroadcast(this.onBroadcast, this));
}

private onBroadcast(broadcast: IBroadcast): void {
Expand Down Expand Up @@ -231,6 +232,7 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
}

private registerSessionListeners(): void {
this.toDisposeOnSessionEnd.push(this.session);
this.toDisposeOnSessionEnd.push(this.session.addListener2(debug.SessionEvents.INITIALIZED, (event: DebugProtocol.InitializedEvent) => {
aria.status(nls.localize('debuggingStarted', "Debugging started."));
this.sendAllBreakpoints().then(() => {
Expand Down Expand Up @@ -710,15 +712,8 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
}

private onSessionEnd(): void {
try {
this.debugStringEditorInputs = lifecycle.dispose(this.debugStringEditorInputs);
} catch (e) {
// an internal module might be open so the dispose can throw -> ignore and continue with stop session.
}

if (this.session) {
const bpsExist = this.model.getBreakpoints().length > 0;
this.session.dispose();
this.telemetryService.publicLog('debugSessionStop', {
type: this.session.getType(),
success: this.session.emittedStopped || !bpsExist,
Expand All @@ -729,7 +724,12 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
}

this.session = null;
this.toDisposeOnSessionEnd = lifecycle.dispose(this.toDisposeOnSessionEnd);
try {
this.toDisposeOnSessionEnd = lifecycle.dispose(this.toDisposeOnSessionEnd);
} catch (e) {
// an internal module might be open so the dispose can throw -> ignore and continue with stop session.
}

this.partService.removeClass('debugging');
this.editorService.focusEditor();

Expand Down Expand Up @@ -857,6 +857,8 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
if (filtered.length === 0) {
const result = this.instantiationService.createInstance(DebugStringEditorInput, source.name, source.uri, source.origin, value, mtype, void 0);
this.debugStringEditorInputs.push(result);
this.toDisposeOnSessionEnd.push(result);

return result;
} else {
return filtered[0];
Expand Down Expand Up @@ -933,12 +935,7 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService
}

public dispose(): void {
if (this.session) {
this.session.disconnect();
this.session = null;
}
this.model.dispose();
this.toDispose = lifecycle.dispose(this.toDispose);
this.toDisposeOnSessionEnd = lifecycle.dispose(this.toDisposeOnSessionEnd);
this.toDispose = lifecycle.dispose(this.toDispose);
}
}
4 changes: 4 additions & 0 deletions src/vs/workbench/parts/debug/node/rawDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,8 @@ export class RawDebugSession extends v8.V8Protocol implements debug.IRawDebugSes
}
this.emit(debug.SessionEvents.SERVER_EXIT);
}

public dispose(): void {
this.disconnect().done(null, errors.onUnexpectedError);
}
}

0 comments on commit 96c3dbc

Please sign in to comment.