Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Kill manually if we dont hear back from delve in a sec #1814
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Aug 8, 2018
1 parent b4c4698 commit d711046
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
Binary file modified Go-latest.vsix
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Go",
"version": "0.6.86-beta.3",
"version": "0.6.86-beta.4",
"publisher": "ms-vscode",
"description": "Rich Go language support for Visual Studio Code",
"author": {
Expand Down
41 changes: 36 additions & 5 deletions src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,11 +566,10 @@ class GoDebugSession extends DebugSession {
this.delve.onclose = (code) => {
if (code !== 0) {
this.sendErrorResponse(response, 3000, 'Failed to continue: Check the debug console for details.');
} else {
this.sendEvent(new TerminatedEvent());
verbose('TerminatedEvent');
}
verbose('Delve is closed');

verbose('Sending TerminatedEvent as delve is closed');
this.sendEvent(new TerminatedEvent());
};

this.delve.connection.then(() => {
Expand Down Expand Up @@ -601,7 +600,19 @@ class GoDebugSession extends DebugSession {

protected disconnectRequest(response: DebugProtocol.DisconnectResponse, args: DebugProtocol.DisconnectArguments): void {
verbose('DisconnectRequest');
this.delve.close().then(() => {
const closeDelvePromise = new Promise((resolve, reject) => {
setTimeout(() => {
if (this.delve.debugProcess) {
verbose('Killing debug process manually as we didnt hear back from delve in time');
killTree(this.delve.debugProcess.pid);
}
resolve();
}, 1000);

this.delve.close().then(() => resolve(), reject);
});

closeDelvePromise.then(() => {
verbose('DisconnectRequest to parent');
super.disconnectRequest(response, args);
verbose('DisconnectResponse');
Expand Down Expand Up @@ -1036,4 +1047,24 @@ function random(low: number, high: number): number {
return Math.floor(Math.random() * (high - low) + low);
}

function killTree(processId: number): void {
if (process.platform === 'win32') {
const TASK_KILL = 'C:\\Windows\\System32\\taskkill.exe';

// when killing a process in Windows its child processes are *not* killed but become root processes.
// Therefore we use TASKKILL.EXE
try {
execSync(`${TASK_KILL} /F /T /PID ${processId}`);
} catch (err) {
}
} else {
// on linux and OS X we kill all direct and indirect child processes as well
try {
const cmd = path.join(__dirname, '../../../scripts/terminateProcess.sh');
spawnSync(cmd, [processId.toString()]);
} catch (err) {
}
}
}

DebugSession.run(GoDebugSession);

0 comments on commit d711046

Please sign in to comment.