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

Commit

Permalink
Halt before detaching to allow dlv to cleanup after itself Fixes #1345
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Jul 20, 2018
1 parent 56a39b0 commit 4e2c08b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 38 deletions.
Binary file modified Go-latest.vsix
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "Go",
"version": "0.6.85-beta.6",
"version": "0.6.85-beta.7",
"publisher": "ms-vscode",
"description": "Rich Go language support for Visual Studio Code",
"author": {
Expand Down
53 changes: 16 additions & 37 deletions src/debugAdapter/goDebug.ts
Expand Up @@ -454,17 +454,22 @@ class Delve {
});
}

close() {
if (!this.debugProcess) {
this.call('Command', [{ name: 'halt' }], (err, out) => {
if (err) return logError('Failed to halt.');
this.call('Restart', this.isApiV1 ? [] : [{ position: '', resetArgs: false, newArgs: [] }], (err, out) => {
close(): Thenable<void> {
return this.callPromise('Command', [{ name: 'halt' }]).then(out => {
if (!this.debugProcess) {
return this.callPromise('Restart', this.isApiV1 ? [] : [{ position: '', resetArgs: false, newArgs: [] }]).then(null, err => {
if (err) return logError('Failed to restart');
});
});
} else {
this.call('Detach', [this.isApiV1 ? true : { Kill: true }], null);
}
}
}, err => {
if (!this.debugProcess && err) {
return logError('Failed to halt.');
}
}).then(() => {
if (this.debugProcess) {
return this.callPromise('Detach', [this.isApiV1 ? true : { Kill: true }]);
}
});
}
}

Expand Down Expand Up @@ -586,16 +591,10 @@ class GoDebugSession extends DebugSession {

protected disconnectRequest(response: DebugProtocol.DisconnectResponse, args: DebugProtocol.DisconnectArguments): void {
verbose('DisconnectRequest');
this.delve.close();

// Timeout to ensure detach is complete.
setTimeout(() => {
if (this.delve.debugProcess) {
killTree(this.delve.debugProcess.pid);
}
this.delve.close().then(() => {
super.disconnectRequest(response, args);
verbose('DisconnectResponse');
}, 1000);
});
}

protected configurationDoneRequest(response: DebugProtocol.ConfigurationDoneResponse, args: DebugProtocol.ConfigurationDoneArguments): void {
Expand Down Expand Up @@ -1026,24 +1025,4 @@ 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 4e2c08b

Please sign in to comment.