Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: stop treating chrome launcher kill() as async #15998

Merged
merged 4 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 6 additions & 19 deletions cli/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,26 +184,13 @@ async function saveResults(runnerResult, flags) {
async function potentiallyKillChrome(launchedChrome) {
if (!launchedChrome) return;

/** @type {NodeJS.Timeout} */
let timeout;
const timeoutPromise = new Promise((_, reject) => {
timeout = setTimeout(reject, 5000, new Error('Timed out waiting to kill Chrome'));
});

return Promise.race([
launchedChrome.kill(),
timeoutPromise,
]).catch(async err => {
const runningProcesses = await psList();
if (!runningProcesses.some(proc => proc.pid === launchedChrome.pid)) {
log.warn('CLI', 'Warning: Chrome process could not be killed because it already exited.');
return;
}
const runningProcesses = await psList();
if (!runningProcesses.some(proc => proc.pid === launchedChrome.pid)) {
log.warn('CLI', 'Warning: Chrome process could not be killed because it already exited.');
return;
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
}

throw new Error(`Couldn't quit Chrome process. ${err}`);
}).finally(() => {
clearTimeout(timeout);
});
launchedChrome.kill();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion cli/test/smokehouse/lighthouse-runners/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async function runBundledLighthouse(url, config, testRunnerOptions) {
};
} finally {
// Clean up and return results.
await launchedChrome.kill();
launchedChrome.kill();
}
}

Expand Down
Loading