diff --git a/lib/server.js b/lib/server.js index c61748a40..ae95b59c7 100644 --- a/lib/server.js +++ b/lib/server.js @@ -372,14 +372,32 @@ class Server extends KarmaEventEmitter { processWrapper.on('SIGINT', () => disconnectBrowsers(process.exitCode)) processWrapper.on('SIGTERM', disconnectBrowsers) - processWrapper.on('uncaughtException', (error) => { + const notKarmaError = (error) => { + // Someone else's socket error? + if (error.toString().includes('ECONNRESET') && + !Object.keys(socketServer.sockets.sockets).length) { + return true + } + return false + } + + const reportError = (error) => { this.log.error(error) + if (notKarmaError(error)) { + return + } + process.emit('infrastructure_error', error) disconnectBrowsers(1) - }) + } processWrapper.on('unhandledRejection', (error) => { - this.log.error(error) - disconnectBrowsers(1) + this.log.error('UnhandledRejection') + reportError(error) + }) + + processWrapper.on('uncaughtException', (error) => { + this.log.error('UncaughtException') + reportError(error) }) }