refactor launchedProcess.killed
This commit is contained in:
parent
4c881cf11c
commit
220ed29dbe
|
|
@ -215,18 +215,18 @@ export async function launchProcess(options: LaunchProcessOptions): Promise<Laun
|
||||||
}
|
}
|
||||||
gracefullyClosing = true;
|
gracefullyClosing = true;
|
||||||
options.log(`[pid=${spawnedProcess.pid}] <gracefully close start>`);
|
options.log(`[pid=${spawnedProcess.pid}] <gracefully close start>`);
|
||||||
await options.attemptToGracefullyClose().catch(() => killProcess());
|
await options.attemptToGracefullyClose().catch(() => killProcess(true));
|
||||||
await waitForCleanup; // Ensure the process is dead and we have cleaned up.
|
await waitForCleanup; // Ensure the process is dead and we have cleaned up.
|
||||||
options.log(`[pid=${spawnedProcess.pid}] <gracefully close end>`);
|
options.log(`[pid=${spawnedProcess.pid}] <gracefully close end>`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method has to be sync to be used in the 'exit' event handler.
|
// This method has to be sync to be used in the 'exit' event handler.
|
||||||
function killProcess() {
|
function killProcess(evenIfAlreadyKilled = false) {
|
||||||
gracefullyCloseSet.delete(gracefullyClose);
|
gracefullyCloseSet.delete(gracefullyClose);
|
||||||
killSet.delete(killProcessAndCleanup);
|
killSet.delete(killProcessAndCleanup);
|
||||||
removeProcessHandlersIfNeeded();
|
removeProcessHandlersIfNeeded();
|
||||||
options.log(`[pid=${spawnedProcess.pid}] <kill>`);
|
options.log(`[pid=${spawnedProcess.pid}] <kill>`);
|
||||||
if (spawnedProcess.pid && !spawnedProcess.killed && !processClosed) {
|
if (spawnedProcess.pid && (evenIfAlreadyKilled || !spawnedProcess.killed) && !processClosed) {
|
||||||
options.log(`[pid=${spawnedProcess.pid}] <will force kill>`);
|
options.log(`[pid=${spawnedProcess.pid}] <will force kill>`);
|
||||||
// Force kill the browser.
|
// Force kill the browser.
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -130,11 +130,7 @@ export class WebServerPlugin implements TestRunnerPlugin {
|
||||||
|
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
const timer = timeout !== 0
|
const timer = timeout !== 0
|
||||||
? setTimeout(() => {
|
? setTimeout(() => reject(new Error(`process didn't close gracefully within timeout, falling back to SIGKILL`)), timeout)
|
||||||
// @ts-expect-error. SIGINT didn't kill the process, but `processLauncher` will only attempt killing it if this is false
|
|
||||||
launchedProcess.killed = false;
|
|
||||||
reject(new Error(`process didn't close gracefully within timeout, falling back to SIGKILL`));
|
|
||||||
}, timeout)
|
|
||||||
: undefined;
|
: undefined;
|
||||||
launchedProcess.once('exit', () => {
|
launchedProcess.once('exit', () => {
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue