Skip to content

Commit bd6c43b

Browse files
committed
Handle terminating DevTools by its real PID
Fixes #1511.
1 parent 6da418b commit bd6c43b

3 files changed

Lines changed: 15 additions & 19 deletions

File tree

‎src/sdk/dev_tools.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ let portToBind = 0;
2323

2424
export class DevTools implements vs.Disposable {
2525
private devToolsStatusBarItem = vs.window.createStatusBarItem(vs.StatusBarAlignment.Right, 100);
26-
private proc: child_process.ChildProcess;
26+
private proc: child_process.ChildProcess | undefined;
27+
private realPid: number | undefined;
2728
/// Resolves to the DevTools URL. This is created immediately when a new process is being spawned so that
2829
/// concurrent launches can wait on the same promise.
29-
private devtoolsUrl: Thenable<string>;
30+
private devtoolsUrl: Thenable<string> | undefined;
3031

3132
constructor(private sdks: Sdks, private analytics: Analytics, private pubGlobal: PubGlobal) { }
3233

@@ -85,6 +86,7 @@ export class DevTools implements vs.Disposable {
8586
const evt = JSON.parse(output);
8687
if (evt.method === "server.started") {
8788
portToBind = evt.params.port;
89+
this.realPid = evt.params.pid;
8890
resolve(`http://${evt.params.host}:${evt.params.port}/`);
8991
}
9092
} catch {
@@ -113,9 +115,18 @@ export class DevTools implements vs.Disposable {
113115

114116
public dispose(): void {
115117
this.devToolsStatusBarItem.dispose();
116-
this.devtoolsUrl = null;
118+
this.devtoolsUrl = undefined;
117119
if (this.proc && !this.proc.killed) {
118120
this.proc.kill();
119121
}
122+
if (this.realPid) {
123+
try {
124+
process.kill(this.realPid);
125+
} catch (e) {
126+
// Sometimes this process will have already gone away (eg. the initial kill() worked)
127+
// so logging here just results in lots of useless info.
128+
}
129+
this.realPid = undefined;
130+
}
120131
}
121132
}

‎test/dart_only/debug/dart_cli.test.ts‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as path from "path";
33
import * as sinon from "sinon";
44
import * as vs from "vscode";
55
import { config } from "../../../src/config";
6-
import { isLinux, platformEol } from "../../../src/debug/utils";
6+
import { platformEol } from "../../../src/debug/utils";
77
import { debugAnywayAction, showErrorsAction } from "../../../src/providers/debug_config_provider";
88
import { fsPath, getRandomInt } from "../../../src/utils";
99
import { fetch } from "../../../src/utils/fetch";
@@ -199,13 +199,6 @@ describe("dart cli debugger", () => {
199199
return;
200200
}
201201

202-
// TODO: Unskip this when we've fixed the orphaned process issue.
203-
// https://github.com/Dart-Code/Dart-Code/issues/1511
204-
if (isLinux) {
205-
this.skip();
206-
return;
207-
}
208-
209202
// Intercept vscode.open so we don't spawn browsers!
210203
const executeCommand = sb.stub(vs.commands, "executeCommand").callThrough();
211204
const open = executeCommand.withArgs("vscode.open", sinon.match.any).resolves();

‎test/flutter_only/debug/flutter_run.test.ts‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as os from "os";
33
import * as path from "path";
44
import * as sinon from "sinon";
55
import * as vs from "vscode";
6-
import { isLinux } from "../../../src/debug/utils";
76
import { fsPath } from "../../../src/utils";
87
import { fetch } from "../../../src/utils/fetch";
98
import { DartDebugClient } from "../../dart_debug_client";
@@ -214,13 +213,6 @@ describe("flutter run debugger (launch)", () => {
214213
return;
215214
}
216215

217-
// TODO: Unskip this when we've fixed the orphaned process issue.
218-
// https://github.com/Dart-Code/Dart-Code/issues/1511
219-
if (isLinux) {
220-
this.skip();
221-
return;
222-
}
223-
224216
// Intercept vscode.open so we don't spawn browsers!
225217
const executeCommand = sb.stub(vs.commands, "executeCommand").callThrough();
226218
const open = executeCommand.withArgs("vscode.open", sinon.match.any).resolves();

0 commit comments

Comments
 (0)