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;
|
||||
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.
|
||||
options.log(`[pid=${spawnedProcess.pid}] <gracefully close end>`);
|
||||
}
|
||||
|
||||
// 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}] <kill>`);
|
||||
if (spawnedProcess.pid && !spawnedProcess.killed && !processClosed) {
|
||||
if (spawnedProcess.pid && (evenIfAlreadyKilled || !spawnedProcess.killed) && !processClosed) {
|
||||
options.log(`[pid=${spawnedProcess.pid}] <will force kill>`);
|
||||
// Force kill the browser.
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -130,11 +130,7 @@ export class WebServerPlugin implements TestRunnerPlugin {
|
|||
|
||||
return new Promise<void>((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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue