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 #
This commit is contained in:
parent
94803fbf53
commit
07b881d9ed
@ -40,6 +40,8 @@ export class PseudoTerminal {
|
||||
|
||||
private initialized: boolean = false;
|
||||
|
||||
private childProcesses = new Set<PseudoTtyProcess>();
|
||||
|
||||
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);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user