fix: change kill to signal the whole process group to terminate (#6859)
* fix: change kill to signal the whole process group to terminate immediately * chore: ignore taskkill errors Co-authored-by: Jan Scheffler <janscheffler@chromium.org>
This commit is contained in:
parent
6970a97df0
commit
0eb9c78617
@ -183,9 +183,16 @@ export class BrowserRunner {
|
|||||||
// If the process failed to launch (for example if the browser executable path
|
// If the process failed to launch (for example if the browser executable path
|
||||||
// is invalid), then the process does not get a pid assigned. A call to
|
// is invalid), then the process does not get a pid assigned. A call to
|
||||||
// `proc.kill` would error, as the `pid` to-be-killed can not be found.
|
// `proc.kill` would error, as the `pid` to-be-killed can not be found.
|
||||||
if (this.proc && this.proc.pid && !this.proc.killed) {
|
if (this.proc && this.proc.pid && pidExists(this.proc.pid)) {
|
||||||
try {
|
try {
|
||||||
this.proc.kill('SIGKILL');
|
if (process.platform === 'win32') {
|
||||||
|
childProcess.exec(`taskkill /pid ${this.proc.pid} /T /F`, () => {});
|
||||||
|
} else {
|
||||||
|
// on linux the process group can be killed with the group id prefixed with
|
||||||
|
// a minus sign. The process group id is the group leader's pid.
|
||||||
|
const processGroupId = -this.proc.pid;
|
||||||
|
process.kill(processGroupId, 'SIGKILL');
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`${PROCESS_ERROR_EXPLANATION}\nError cause: ${error.stack}`
|
`${PROCESS_ERROR_EXPLANATION}\nError cause: ${error.stack}`
|
||||||
@ -294,3 +301,15 @@ function waitForWSEndpoint(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pidExists(pid: number): boolean {
|
||||||
|
try {
|
||||||
|
return process.kill(pid, 0);
|
||||||
|
} catch (error) {
|
||||||
|
if (error && error.code && error.code === 'ESRCH') {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user