From 4592888e6b97bc31c8ebc1cd924612f604228bff Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 13 May 2024 14:32:25 -0700 Subject: [PATCH 1/3] cli: stop treating chrome launcher kill() as async --- cli/run.js | 25 +++++-------------- .../smokehouse/lighthouse-runners/bundle.js | 2 +- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/cli/run.js b/cli/run.js index 6366ce6c7be2..d72c099dcb3c 100644 --- a/cli/run.js +++ b/cli/run.js @@ -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; + } - throw new Error(`Couldn't quit Chrome process. ${err}`); - }).finally(() => { - clearTimeout(timeout); - }); + launchedChrome.kill(); } /** 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(); } } From 440d69ac861e8eac2857e760ce5b09c16166e2fe Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Tue, 14 May 2024 09:47:57 -0700 Subject: [PATCH 2/3] remove pslist --- cli/run.js | 30 +++++------------------------- package.json | 1 - 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/cli/run.js b/cli/run.js index d72c099dcb3c..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,23 +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; - - 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; - } - - launchedChrome.kill(); -} - /** * @param {string} url * @param {LH.CliFlags} flags @@ -201,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); @@ -234,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. @@ -252,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/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", From aad9c409652fdf8b9479e5ee11b65aaf10523b64 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Tue, 14 May 2024 09:48:06 -0700 Subject: [PATCH 3/3] yarn --- yarn.lock | 5 ----- 1 file changed, 5 deletions(-) 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"