diff --git a/src/node/server.js b/src/node/server.js index 0f0b0147f..6986e527e 100755 --- a/src/node/server.js +++ b/src/node/server.js @@ -111,10 +111,16 @@ exports.start = async () => { stats.gauge('memoryUsage', () => process.memoryUsage().rss); stats.gauge('memoryUsageHeap', () => process.memoryUsage().heapUsed); - process.on('uncaughtException', (err) => exports.exit(err)); + process.on('uncaughtException', (err) => { + logger.debug(`uncaught exception: ${err.stack || err}`); + exports.exit(err); + }); // As of v14, Node.js does not exit when there is an unhandled Promise rejection. Convert an // unhandled rejection into an uncaught exception, which does cause Node.js to exit. - process.on('unhandledRejection', (err) => { throw err; }); + process.on('unhandledRejection', (err) => { + logger.debug(`unhandled rejection: ${err.stack || err}`); + throw err; + }); for (const signal of ['SIGINT', 'SIGTERM']) { // Forcibly remove other signal listeners to prevent them from terminating node before we are @@ -219,6 +225,7 @@ exports.exit = async (err = null) => { process.exit(1); } } + if (!exitCalled) logger.info('Exiting...'); exitCalled = true; switch (state) { case State.STARTING: @@ -241,7 +248,6 @@ exports.exit = async (err = null) => { default: throw new Error(`unknown State: ${state.toString()}`); } - logger.info('Exiting...'); exitGate = new Gate(); state = State.EXITING; exitGate.resolve();