Skip to content

Commit

Permalink
debug: support termiante request
Browse files Browse the repository at this point in the history
fixes #54384
  • Loading branch information
isidorn committed Jul 16, 2018
1 parent 0344920 commit 22e16c7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/debug/common/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export interface IRawSession {
evaluate(args: DebugProtocol.EvaluateArguments): TPromise<DebugProtocol.EvaluateResponse>;

readonly capabilities: DebugProtocol.Capabilities;
disconnect(restart?: boolean, force?: boolean): TPromise<DebugProtocol.DisconnectResponse>;
terminate(restart?: boolean): TPromise<DebugProtocol.TerminateResponse>;
custom(request: string, args: any): TPromise<DebugProtocol.Response>;
onDidEvent: Event<DebugProtocol.Event>;
onDidInitialize: Event<DebugProtocol.InitializedEvent>;
Expand Down
19 changes: 10 additions & 9 deletions src/vs/workbench/parts/debug/electron-browser/debugService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,16 @@ export class DebugService implements debug.IDebugService {
(<RawDebugSession>session.raw).attach(session.configuration);
});
} else {
raw.disconnect().done(undefined, errors.onUnexpectedError);
this.doCreateSession(session.raw.root, { resolved: session.configuration, unresolved: session.unresolvedConfiguration }, session.getId());
const root = raw.root;
raw.dispose();
this.doCreateSession(root, { resolved: session.configuration, unresolved: session.unresolvedConfiguration }, session.getId());
}

return;
}

if (broadcast.channel === EXTENSION_TERMINATE_BROADCAST_CHANNEL) {
raw.disconnect().done(undefined, errors.onUnexpectedError);
raw.terminate().done(undefined, errors.onUnexpectedError);
return;
}

Expand Down Expand Up @@ -292,7 +293,7 @@ export class DebugService implements debug.IDebugService {
return raw.configurationDone().done(null, e => {
// Disconnect the debug session on configuration done error #10596
if (raw) {
raw.disconnect().done(null, errors.onUnexpectedError);
raw.dispose();
}
this.notificationService.error(e.message);
});
Expand Down Expand Up @@ -342,7 +343,7 @@ export class DebugService implements debug.IDebugService {
if (event.body && event.body.restart && session) {
this.restartSession(session, event.body.restart).done(null, err => this.notificationService.error(err.message));
} else {
raw.disconnect().done(null, errors.onUnexpectedError);
raw.dispose();
}
}
}));
Expand Down Expand Up @@ -975,7 +976,7 @@ export class DebugService implements debug.IDebugService {
this.telemetryService.publicLog('debugMisconfiguration', { type: resolved ? resolved.type : undefined, error: errorMessage });
this.updateStateAndEmit(raw.getId(), debug.State.Inactive);
if (!raw.disconnected) {
raw.disconnect().done(null, errors.onUnexpectedError);
raw.dispose();
} else if (session) {
this.model.removeSession(session.getId());
}
Expand Down Expand Up @@ -1115,7 +1116,7 @@ export class DebugService implements debug.IDebugService {
// Do not run preLaunch and postDebug tasks for automatic restarts
this.skipRunningTask = !!restartData;

return session.raw.disconnect(true).then(() => {
return session.raw.terminate(true).then(() => {
if (strings.equalsIgnoreCase(session.configuration.type, 'extensionHost') && session.raw.root) {
return this.broadcastService.broadcast({
channel: EXTENSION_RELOAD_BROADCAST_CHANNEL,
Expand Down Expand Up @@ -1157,12 +1158,12 @@ export class DebugService implements debug.IDebugService {

public stopSession(session: debug.ISession): TPromise<any> {
if (session) {
return session.raw.disconnect(false, true);
return session.raw.terminate();
}

const sessions = this.model.getSessions();
if (sessions.length) {
return TPromise.join(sessions.map(s => s.raw.disconnect(false, true)));
return TPromise.join(sessions.map(s => s.raw.terminate(false)));
}

this.sessionStates.clear();
Expand Down
42 changes: 26 additions & 16 deletions src/vs/workbench/parts/debug/electron-browser/rawDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class RawDebugSession implements debug.IRawSession {
private cachedInitServerP: TPromise<void>;
private startTime: number;
public disconnected: boolean;
private terminated: boolean;
private sentPromises: TPromise<DebugProtocol.Response>[];
private _capabilities: DebugProtocol.Capabilities;
private allThreadsContinued: boolean;
Expand Down Expand Up @@ -339,24 +340,13 @@ export class RawDebugSession implements debug.IRawSession {
return this.send<DebugProtocol.CompletionsResponse>('completions', args);
}

public disconnect(restart = false, force = false): TPromise<DebugProtocol.DisconnectResponse> {
if (this.disconnected && force) {
return this.stopServer();
}

// Cancel all sent promises on disconnect so debug trees are not left in a broken state #3666.
// Give a 1s timeout to give a chance for some promises to complete.
setTimeout(() => {
this.sentPromises.forEach(p => p && p.cancel());
this.sentPromises = [];
}, 1000);

if (this.debugAdapter && !this.disconnected) {
// point of no return: from now on don't report any errors
this.disconnected = true;
return this.send('disconnect', { restart }, false).then(() => this.stopServer(), () => this.stopServer());
public terminate(restart = false): TPromise<DebugProtocol.TerminateResponse> {
if (this.capabilities.supportsTerminateRequest && !this.terminated) {
this.terminated = true;
return this.send('terminate', { restart });
}

this.dispose(restart);
return TPromise.as(null);
}

Expand Down Expand Up @@ -483,6 +473,26 @@ export class RawDebugSession implements debug.IRawSession {
});
}

public dispose(restart = false): void {
if (this.disconnected) {
this.stopServer().done(undefined, errors.onUnexpectedError);
} else {

// Cancel all sent promises on disconnect so debug trees are not left in a broken state #3666.
// Give a 1s timeout to give a chance for some promises to complete.
setTimeout(() => {
this.sentPromises.forEach(p => p && p.cancel());
this.sentPromises = [];
}, 1000);

if (this.debugAdapter && !this.disconnected) {
// point of no return: from now on don't report any errors
this.disconnected = true;
this.send('disconnect', { restart }, false).then(() => this.stopServer(), () => this.stopServer()).done(undefined, errors.onUnexpectedError);
}
}
}

private stopServer(): TPromise<any> {

if (/* this.socket !== null */ this.debugAdapter instanceof SocketDebugAdapter) {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/debug/test/common/mockDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export class MockSession implements IRawSession {
return TPromise.as(null);
}

public disconnect(restart?: boolean, force?: boolean): TPromise<DebugProtocol.DisconnectResponse> {
public terminate(restart = false): TPromise<DebugProtocol.TerminateResponse> {
return TPromise.as(null);
}

Expand Down

0 comments on commit 22e16c7

Please sign in to comment.