From da2400417896009c7f020dbbd26c22fd5ad1d21c Mon Sep 17 00:00:00 2001 From: Sam Saccone Date: Wed, 24 May 2017 20:56:35 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=98=88=20Fix=20disconnect=20promise=20rac?= =?UTF-8?q?e.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is possible that we were resolving the gather chain before we had disconnected. When manually launching and killing chrome this can race and result in an error to the user. This fixes that problem. \o/. Fixes #2337 --- Test plan: Run launcher with: ```ts const lighthouse = require('lighthouse'); import {launch} from './chrome-launcher'; async function runLighthouse(url: string) { const opts = { chromeFlags: ['--headless'], }; const chrome = await launch(opts); const flags = { output: 'json', port: chrome.port, }; const results = await lighthouse(url, flags); process.on('uncaughtException', (e: any) => { console.log(e); }); await chrome.kill(); return results; } runLighthouse('https://example.com'); ``` Without this patch, and then run it with the patch. Observe it now working. --- lighthouse-core/gather/gather-runner.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lighthouse-core/gather/gather-runner.js b/lighthouse-core/gather/gather-runner.js index 5de4e7e78974..2a8b8de0f5ad 100644 --- a/lighthouse-core/gather/gather-runner.js +++ b/lighthouse-core/gather/gather-runner.js @@ -118,10 +118,8 @@ class GatherRunner { } static disposeDriver(driver) { - // We dont need to hold up the reporting for the reload/disconnect, - // so we will not return a promise in here. log.log('status', 'Disconnecting from browser...'); - driver.disconnect().catch(err => { + return driver.disconnect().catch(err => { // Ignore disconnecting error if browser was already closed. // See https://github.com/GoogleChrome/lighthouse/issues/1583 if (!(/close\/.*status: 500$/.test(err.message))) {