server: Improve log messages when exiting

This commit is contained in:
Richard Hansen 2021-02-18 02:05:55 -05:00 committed by John McLear
parent 449b03d7e8
commit 4c6cb53d18

View file

@ -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();