diff --git a/cli/run.js b/cli/run.js index 6366ce6c7be2..195771f605a7 100644 --- a/cli/run.js +++ b/cli/run.js @@ -9,7 +9,6 @@ import path from 'path'; import os from 'os'; -import psList from 'ps-list'; import * as ChromeLauncher from 'chrome-launcher'; import yargsParser from 'yargs-parser'; import log from 'lighthouse-logger'; @@ -176,36 +175,6 @@ async function saveResults(runnerResult, flags) { } } -/** - * Attempt to kill the launched Chrome, if defined. - * @param {ChromeLauncher.LaunchedChrome=} launchedChrome - * @return {Promise} - */ -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; - } - - throw new Error(`Couldn't quit Chrome process. ${err}`); - }).finally(() => { - clearTimeout(timeout); - }); -} - /** * @param {string} url * @param {LH.CliFlags} flags @@ -214,12 +183,10 @@ async function potentiallyKillChrome(launchedChrome) { */ async function runLighthouse(url, flags, config) { /** @param {any} reason */ - async function handleTheUnhandled(reason) { + function handleTheUnhandled(reason) { process.stderr.write(`Unhandled Rejection. Reason: ${reason}\n`); - await potentiallyKillChrome(launchedChrome).catch(() => {}); - setTimeout(_ => { - process.exit(1); - }, 100); + launchedChrome?.kill(); + process.exit(1); } process.on('unhandledRejection', handleTheUnhandled); @@ -247,7 +214,7 @@ async function runLighthouse(url, flags, config) { await saveResults(runnerResult, flags); } - await potentiallyKillChrome(launchedChrome); + launchedChrome?.kill(); process.removeListener('unhandledRejection', handleTheUnhandled); // Runtime errors indicate something was *very* wrong with the page result. @@ -265,7 +232,7 @@ async function runLighthouse(url, flags, config) { return runnerResult; } catch (err) { - await potentiallyKillChrome(launchedChrome).catch(() => {}); + launchedChrome?.kill(); return printErrorAndExit(err); } } diff --git a/cli/test/smokehouse/lighthouse-runners/bundle.js b/cli/test/smokehouse/lighthouse-runners/bundle.js index 765aaf1fc6e2..b8ca0be49387 100644 --- a/cli/test/smokehouse/lighthouse-runners/bundle.js +++ b/cli/test/smokehouse/lighthouse-runners/bundle.js @@ -97,7 +97,7 @@ async function runBundledLighthouse(url, config, testRunnerOptions) { }; } finally { // Clean up and return results. - await launchedChrome.kill(); + launchedChrome.kill(); } } diff --git a/package.json b/package.json index d3c92381af13..ffe28ba341f4 100644 --- a/package.json +++ b/package.json @@ -198,7 +198,6 @@ "metaviewport-parser": "0.3.0", "open": "^8.4.0", "parse-cache-control": "1.0.1", - "ps-list": "^8.0.0", "puppeteer-core": "^22.6.5", "robots-parser": "^3.0.1", "semver": "^5.3.0", diff --git a/yarn.lock b/yarn.lock index 11eb4ccfc068..aaac9442a602 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6017,11 +6017,6 @@ proxy-from-env@^1.1.0: resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2" integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg== -ps-list@^8.0.0: - version "8.0.0" - resolved "https://registry.yarnpkg.com/ps-list/-/ps-list-8.0.0.tgz#ee622c04a16ac0b29be65d7d920c1fb36c8383d4" - integrity sha512-rBBL6jp5Ccc5fy7p1Os5wDkXlJm5PeLCP2mVz1wLqEtKGo+d19oDApqVbePJoOxNlWeaxJxe28qahc3KWj9ePg== - psl@^1.1.28: version "1.8.0" resolved "https://registry.yarnpkg.com/psl/-/psl-1.8.0.tgz#9326f8bcfb013adcc005fdff056acce020e51c24"