Unable to catch a intermittent and fatal "Error: not opened"
See original GitHub issueI 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:
- Created 4 years ago
- Reactions:1
- Comments:7
Top GitHub Comments
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.Glad we got it sorted out! Feel free to circle back around and re-open if 5.0 still poses this problem