server: Improve log messages when exiting

pull/4822/head
Richard Hansen 2021-02-18 02:05:55 -05:00 committed by John McLear
parent 449b03d7e8
commit 4c6cb53d18
1 changed files with 9 additions and 3 deletions

View File

@ -111,10 +111,16 @@ exports.start = async () => {
stats.gauge('memoryUsage', () => process.memoryUsage().rss); stats.gauge('memoryUsage', () => process.memoryUsage().rss);
stats.gauge('memoryUsageHeap', () => process.memoryUsage().heapUsed); 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 // 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. // 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']) { for (const signal of ['SIGINT', 'SIGTERM']) {
// Forcibly remove other signal listeners to prevent them from terminating node before we are // 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); process.exit(1);
} }
} }
if (!exitCalled) logger.info('Exiting...');
exitCalled = true; exitCalled = true;
switch (state) { switch (state) {
case State.STARTING: case State.STARTING:
@ -241,7 +248,6 @@ exports.exit = async (err = null) => {
default: default:
throw new Error(`unknown State: ${state.toString()}`); throw new Error(`unknown State: ${state.toString()}`);
} }
logger.info('Exiting...');
exitGate = new Gate(); exitGate = new Gate();
state = State.EXITING; state = State.EXITING;
exitGate.resolve(); exitGate.resolve();