From 220ed29dbeb38fe6900a1a6d5509eb47f072a61f Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Thu, 7 Nov 2024 12:12:02 +0100 Subject: [PATCH] refactor launchedProcess.killed --- packages/playwright-core/src/utils/processLauncher.ts | 6 +++--- packages/playwright/src/plugins/webServerPlugin.ts | 6 +----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/playwright-core/src/utils/processLauncher.ts b/packages/playwright-core/src/utils/processLauncher.ts index 4e6c1030b2..d64589b79b 100644 --- a/packages/playwright-core/src/utils/processLauncher.ts +++ b/packages/playwright-core/src/utils/processLauncher.ts @@ -215,18 +215,18 @@ export async function launchProcess(options: LaunchProcessOptions): Promise`); - await options.attemptToGracefullyClose().catch(() => killProcess()); + await options.attemptToGracefullyClose().catch(() => killProcess(true)); await waitForCleanup; // Ensure the process is dead and we have cleaned up. options.log(`[pid=${spawnedProcess.pid}] `); } // This method has to be sync to be used in the 'exit' event handler. - function killProcess() { + function killProcess(evenIfAlreadyKilled = false) { gracefullyCloseSet.delete(gracefullyClose); killSet.delete(killProcessAndCleanup); removeProcessHandlersIfNeeded(); options.log(`[pid=${spawnedProcess.pid}] `); - if (spawnedProcess.pid && !spawnedProcess.killed && !processClosed) { + if (spawnedProcess.pid && (evenIfAlreadyKilled || !spawnedProcess.killed) && !processClosed) { options.log(`[pid=${spawnedProcess.pid}] `); // Force kill the browser. try { diff --git a/packages/playwright/src/plugins/webServerPlugin.ts b/packages/playwright/src/plugins/webServerPlugin.ts index 5c2451521c..e879f109fa 100644 --- a/packages/playwright/src/plugins/webServerPlugin.ts +++ b/packages/playwright/src/plugins/webServerPlugin.ts @@ -130,11 +130,7 @@ export class WebServerPlugin implements TestRunnerPlugin { return new Promise((resolve, reject) => { const timer = timeout !== 0 - ? setTimeout(() => { - // @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) + ? setTimeout(() => reject(new Error(`process didn't close gracefully within timeout, falling back to SIGKILL`)), timeout) : undefined; launchedProcess.once('exit', () => { clearTimeout(timer);