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

Chromelauncher error on when killing instance #2337

Closed
li-kai opened this issue May 23, 2017 · 6 comments · Fixed by #2359
Closed

Chromelauncher error on when killing instance #2337

li-kai opened this issue May 23, 2017 · 6 comments · Fixed by #2359
Assignees

Comments

@li-kai
Copy link

li-kai commented May 23, 2017

I've been trying to get headless chrome running, but I've been getting Error: read ECONNRESET which I've been able to reproduce consistently here:

const lighthouse = require('lighthouse');
const chromeLauncher = require('lighthouse/chrome-launcher/chrome-launcher');

async function runLighthouse(url) {
  const opts = {
    chromeFlags: ['--headless'],
  };
  const chrome = await chromeLauncher.launch(opts);
  const flags = {
    output: 'json',
    port: chrome.port,
  };
  const results = await lighthouse(url, flags);
  await chrome.kill();
  return results;
}

runLighthouse('https://example.com');

Node versions used: 6.8.0 & 7.9.0
Lighthouse: 2.0.0
OS: Mac OS Sierra 10.12.4 & Ubuntu LTS 14.04 (Travis)

I've been able to fix this by either catching the process.on('uncaughtException', ... event in chrome-launcher.js, or setting a timeout on the await chrome.kill(); code. Neither of which I believe is ideal since I'm quite new to Node.

@ebidel
Copy link
Contributor

ebidel commented May 23, 2017

I've been seeing this too when using headless Chrome. We need to investigate.

Until then, the workaround is what you're doing...introduce a small delay before killing chrome. See also #1931 (comment).

@samccone
Copy link
Contributor

Thanks for the test case, we will get to the bottom of this.

@samccone
Copy link
Contributor

Confirmed this is 100% reproducible on headless but not on normal chrome.
Wrapping the code in a 2 second timeout fixes things, but that is not a real fix. My guess is that this is a behavior difference in lighthouse in headless, and is not related to launcher directly.

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');

samccone added a commit that referenced this issue May 25, 2017
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.
@ebidel
Copy link
Contributor

ebidel commented Jun 7, 2017

Circling back. --headless should work without the delay now. Be sure to update to LH 2.1.0.

@samccone
Copy link
Contributor

samccone commented Jun 7, 2017

ack, the root of this bug was in lighthouse, headless just made it happen more 🗡

@bliu23
Copy link

bliu23 commented Jul 26, 2017

Is this actually fixed? I'm launching headless chrome with chrome launcher v0.3.2 and running into this issue.

Should I instead be using lighthouse and importing the chrome-launcher module?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants