fix(core): handle killing child processes of continuous tasks on Windows (#31296)
This PR fixes an issue where running `nx e2e <proj>` on Windows does not kill the underlying dev/preview server when the e2e task ends. Repro: 1. `npx create-nx-workspace@latest repro --preset=react-monorepo --e2eTestRunner=playwright --appName=demo` 2. `cd repro && npx nx e2e demo-e2e` This will leave the preview server running on port `4300`, and you have to `netstat -ano | findstr :4300` to find the PID and kill it. https://www.loom.com/share/fcbea53cdff543a98f4d4c8377027ee0 ## Current Behavior Continuous task does not kill the process correctly once discrete task ends. ## Expected Behavior Processes are killed correctly once task is done running. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #31235
This commit is contained in:
parent
ca4ad45c84
commit
7e0719cc0a
@ -359,21 +359,15 @@ class RunningNodeProcess implements RunningTask {
|
||||
|
||||
kill(signal?: NodeJS.Signals): Promise<void> {
|
||||
return new Promise<void>((res, rej) => {
|
||||
if (process.platform === 'win32') {
|
||||
if (this.childProcess.kill(signal)) {
|
||||
res();
|
||||
} else {
|
||||
rej('Unable to kill process');
|
||||
}
|
||||
} else {
|
||||
treeKill(this.childProcess.pid, signal, (err) => {
|
||||
if (err) {
|
||||
// On Windows, tree-kill (which uses taskkill) may fail when the process or its child process is already terminated.
|
||||
// Ignore the errors, otherwise we will log them unnecessarily.
|
||||
if (err && process.platform !== 'win32') {
|
||||
rej(err);
|
||||
} else {
|
||||
res();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user