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 e7f2db4 commit dfc1682
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 16 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
63 changes: 48 additions & 15 deletions src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,26 +460,39 @@ class Delve {

close(): Thenable<void> {
verbose('HaltRequest');
return this.callPromise('Command', [{ name: 'halt' }]).then(out => {
verbose('HaltResponse');
if (!this.debugProcess) {
verbose('RestartRequest');
return this.callPromise('Restart', this.isApiV1 ? [] : [{ position: '', resetArgs: false, newArgs: [] }]).then(null, err => {
verbose('RestartResponse');
if (err) return logError('Failed to restart');
});
}
}, err => {
verbose('HaltResponse');
if (!this.debugProcess && err) {
return logError('Failed to halt - ' + err.toString());

const haltPromise = new Promise((resolve, reject) => {
if (this.debugProcess) {
setTimeout(() => {
verbose('Killing debug process manually as we didnt hear back from delve in time');
killTree(this.debugProcess.pid);
reject();
}, 1000);
}
}).then(() => {

this.callPromise('Command', [{ name: 'halt' }]).then(() => {
verbose('HaltResponse');
if (!this.debugProcess) {
verbose('RestartRequest');
return this.callPromise('Restart', this.isApiV1 ? [] : [{ position: '', resetArgs: false, newArgs: [] }]).then(null, err => {
verbose('RestartResponse');
if (err) return logError('Failed to restart');
});
}
}, err => {
verbose('HaltResponse');
if (!this.debugProcess && err) {
return logError('Failed to halt - ' + err.toString());
}
}).then(() => resolve(), reject);
});

return haltPromise.then(() => {
if (this.debugProcess) {
verbose('DetachRequest');
return this.callPromise('Detach', [this.isApiV1 ? true : { Kill: true }]).then(() => verbose('DetachResponse'));
}
});
}, null);
}
}

Expand Down Expand Up @@ -1034,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 dfc1682

Please sign in to comment.