From 07b881d9ed060473b96a8ae8738d0de4080d2ae6 Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Tue, 29 Apr 2025 20:58:36 -0400 Subject: [PATCH] fix(core): kill child processes when pseudo terminal shutsdown (#30935) ## Current Behavior The PseudoTerminal does not kill it's child processes when it shuts down. ## Expected Behavior The PseudoTerminal will kill it's child processes when it shuts down. ## Related Issue(s) Fixes # --- packages/nx/src/tasks-runner/pseudo-terminal.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/nx/src/tasks-runner/pseudo-terminal.ts b/packages/nx/src/tasks-runner/pseudo-terminal.ts index 702961951a..ae2c4312a0 100644 --- a/packages/nx/src/tasks-runner/pseudo-terminal.ts +++ b/packages/nx/src/tasks-runner/pseudo-terminal.ts @@ -40,6 +40,8 @@ export class PseudoTerminal { private initialized: boolean = false; + private childProcesses = new Set(); + static isSupported() { return process.stdout.isTTY && supportedPtyPlatform(); } @@ -55,6 +57,11 @@ export class PseudoTerminal { } shutdown() { + for (const cp of this.childProcesses) { + try { + cp.kill(); + } catch {} + } if (this.initialized) { this.pseudoIPC.close(); } @@ -76,7 +83,7 @@ export class PseudoTerminal { tty?: boolean; } = {} ) { - return new PseudoTtyProcess( + const cp = new PseudoTtyProcess( this.rustPseudoTerminal, this.rustPseudoTerminal.runCommand( command, @@ -87,6 +94,8 @@ export class PseudoTerminal { tty ) ); + this.childProcesses.add(cp); + return cp; } async fork( @@ -121,6 +130,7 @@ export class PseudoTerminal { id, this.pseudoIPC ); + this.childProcesses.add(cp); await this.pseudoIPC.waitForChildReady(id);