question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to catch a intermittent and fatal "Error: not opened"

See original GitHub issue

I am intermittently experiencing the Error: not opened and ECONNREFUSED on the site. I am running in a loop (trying the below script again and again until failure). I know the page I am using is pretty bad quality- that’s why I am using it for testing! My custom timeout will launch, try and then kill chrome between 0 and say 5 times in a row before the error is thrown.

What is irritating, is that I can’t catch this error, which means that sometimes my chrome instance (and the corresponding ~8 processes) doesn’t get killed, even though node has crashed. In my production environment, this will mean that if this happens repeatedly, chrome instances/processes will pile up and eventually choke my server resources! I’d like to be able to catch fatal lighthouse errors and fail gracefully!

node modules:

lighthouse 5.0.0 
chrome-launcher 0.10.7

node wrapper:

const url = 'http://pcfanatics.pk/';

  const chromeFlags = [
    '--headless',
    '--disable-gpu',
    '--no-sandbox',
    '--ignoreHTTPSErrors',
    '--disable-web-security',
    '--incognito',
  ];

  const chrome = await (chromeLauncher.launch)({chromeFlags: chromeFlags});
  const port = chrome.port;

  const lhFlags = {
    disableDeviceEmulation: true,
    disableStorageReset: true,
    throttlingMethod: 'provided',
    maxWaitForLoad: process.env.MAX_WAIT_FOR_LOAD,
    port: port,
    logLevel: 'info',
  };

  const timer = setTimeout(async () => {
    await chrome.kill().then(()=>{
      console.log('Chrome has been killed');
    });
  }, 20000).unref();

  const tryLighthouse = async () => {
    try {
      const result = await lighthouse(url, lhFlags, require('../../lighthouseConfig'));
      return result;
    } catch (e) {
      console.error(e.stack||e);
    }
  };

  const result = await tryLighthouse();

Failure log:

 Driver:warn Timed out waiting for page load. Checking if page is hung... +15s
  Driver:warn Page appears to be hung, killing JavaScript... +2ms
  status Disconnecting from browser... +1ms
Error: not opened
    at WebSocket.send (C:\Users\misha\upugo\upugo-lighthouse-audits\node_modules\ws\lib\WebSocket.js:344:18)
    at CriConnection.sendRawMessage (C:\Users\misha\upugo\upugo-lighthouse-audits\node_modules\lighthouse\lighthouse-core\gather\connections\cri.js:172:14)
    at CriConnection.sendCommand (C:\Users\misha\upugo\upugo-lighthouse-audits\node_modules\lighthouse\lighthouse-core\gather\connections\connection.js:65:10)
    at Driver._innerSendCommand (C:\Users\misha\upugo\upugo-lighthouse-audits\node_modules\lighthouse\lighthouse-core\gather\driver.js:310:29)
    at Promise (C:\Users\misha\upugo\upugo-lighthouse-audits\node_modules\lighthouse\lighthouse-core\gather\driver.js:284:35)
    at new Promise (<anonymous>)
    at Driver.sendCommand (C:\Users\misha\upugo\upugo-lighthouse-audits\node_modules\lighthouse\lighthouse-core\gather\driver.js:275:12)
    at C:\Users\misha\upugo\upugo-lighthouse-audits\node_modules\lighthouse\lighthouse-core\gather\driver.js:878:22
events.js:167
      throw er; // Unhandled 'error' event
      ^

Error: connect ECONNREFUSED 127.0.0.1:56011
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1113:14)
Emitted 'error' event at:
    at Socket.socketErrorListener (_http_client.js:391:9)
    at Socket.emit (events.js:182:13)
    at Socket.EventEmitter.emit (domain.js:442:20)
    at emitErrorNT (internal/streams/destroy.js:82:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

1reaction
patrickhulcecommented, May 22, 2019

Are you 100% positive this is with lighthouse 5.0?

This was a known bug in 4.x and should be fixed by https://github.com/GoogleChrome/lighthouse/pull/8583. Additionally, the stack trace in your error message points to sendRawMessage at its line count in 4.x. In 5.0 the line referenced by your stack trace points to the end of the file.

0reactions
patrickhulcecommented, May 22, 2019

Glad we got it sorted out! Feel free to circle back around and re-open if 5.0 still poses this problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug #63413 :: Intermittent warning and fatal error on require ...
It seems that while file_exists() always returns true (the require() statements are always executed), the calls to require() fail intermittently ...
Read more >
31 - Stack Overflow
Workaround for git connection errors # fatal: unable to access 'https://dev.azure.com/MyOrg/my-project/_git/my-repo/': OpenSSL SSL_connect: ...
Read more >
Resolving could not open a connection to SQL Server errors
Make sure the SQL services are running. You can check the SQL Server services by using the SC command opening SQL Server Configuration...
Read more >
Intermittent status 83 on SAN client backup when pipe open is ...
The Job Details will show the status 83 following a pipe open failure'. The job was active, but never started transferring any data....
Read more >
Resolve Acrobat intermittent crashes on Windows
Solution 2: Run Repair Acrobat Installation while no other applications are running. Close all open applications.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found