Skip to content

Commit ff9357c

Browse files
BootBlockDanTup
authored andcommitted
Prevent sending multiple kill signals to the same PID
Helps with #2538.
1 parent f57686f commit ff9357c

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

‎src/debug/dart_debug_impl.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ const trailingSemicolonPattern = new RegExp(`;\\s*$`, "m");
3838
export class DartDebugSession extends DebugSession {
3939
// TODO: Tidy all this up
4040
protected childProcess?: SpawnedProcess | RemoteEditorTerminalProcess;
41-
protected additionalPidsToTerminate: number[] = [];
41+
42+
/** The additional process IDs to terminate when terminating a debugging session.
43+
*
44+
* A Set is used so a Process ID does not appear multiple times within the collection as
45+
* that can cause a (eg. testing) session to be terminated prematurely while waiting for it to end.
46+
*/
47+
protected readonly additionalPidsToTerminate = new Set<number>();
48+
4249
protected expectAdditionalPidToTerminate = false;
4350
private additionalPidCompleter = new PromiseCompleter<void>();
4451
// We normally track the pid from Observatory to terminate the VM afterwards, but for Flutter Run it's
@@ -597,7 +604,7 @@ export class DartDebugSession extends DebugSession {
597604
}
598605

599606
protected recordAdditionalPid(pid: number) {
600-
this.additionalPidsToTerminate.push(pid);
607+
this.additionalPidsToTerminate.add(pid);
601608
this.additionalPidCompleter.resolve();
602609
}
603610

@@ -723,7 +730,7 @@ export class DartDebugSession extends DebugSession {
723730
this.isTerminating = true;
724731
this.sendEvent(new Event("dart.terminating", { message: "Terminating debug session..." }));
725732

726-
if (this.expectAdditionalPidToTerminate && !this.additionalPidsToTerminate.length) {
733+
if (this.expectAdditionalPidToTerminate && !this.additionalPidsToTerminate.size) {
727734
this.log(`Waiting for main process PID before terminating`);
728735
this.sendEvent(new Event("dart.terminating", { message: "Waiting for process..." }));
729736
const didGetPid = await this.raceIgnoringErrors(() => this.additionalPidCompleter.promise, 20000);

0 commit comments

Comments
 (0)