Skip to content

Commit 07b881d

Browse files
authored
fix(core): kill child processes when pseudo terminal shutsdown (#30935)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> The PseudoTerminal does not kill it's child processes when it shuts down. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> The PseudoTerminal will kill it's child processes when it shuts down. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
1 parent 94803fb commit 07b881d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/nx/src/tasks-runner/pseudo-terminal.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export class PseudoTerminal {
4040

4141
private initialized: boolean = false;
4242

43+
private childProcesses = new Set<PseudoTtyProcess>();
44+
4345
static isSupported() {
4446
return process.stdout.isTTY && supportedPtyPlatform();
4547
}
@@ -55,6 +57,11 @@ export class PseudoTerminal {
5557
}
5658

5759
shutdown() {
60+
for (const cp of this.childProcesses) {
61+
try {
62+
cp.kill();
63+
} catch {}
64+
}
5865
if (this.initialized) {
5966
this.pseudoIPC.close();
6067
}
@@ -76,7 +83,7 @@ export class PseudoTerminal {
7683
tty?: boolean;
7784
} = {}
7885
) {
79-
return new PseudoTtyProcess(
86+
const cp = new PseudoTtyProcess(
8087
this.rustPseudoTerminal,
8188
this.rustPseudoTerminal.runCommand(
8289
command,
@@ -87,6 +94,8 @@ export class PseudoTerminal {
8794
tty
8895
)
8996
);
97+
this.childProcesses.add(cp);
98+
return cp;
9099
}
91100

92101
async fork(
@@ -121,6 +130,7 @@ export class PseudoTerminal {
121130
id,
122131
this.pseudoIPC
123132
);
133+
this.childProcesses.add(cp);
124134

125135
await this.pseudoIPC.waitForChildReady(id);
126136

0 commit comments

Comments
 (0)