Properly await termination.

This commit is contained in:
Mark H. Wood
2023-08-22 15:46:55 -04:00
parent 6709c3bb5f
commit 4449737aed

View File

@@ -535,10 +535,12 @@ function createHttpsServer(keys) {
// Graceful shutdown when signalled // Graceful shutdown when signalled
const terminator = createHttpTerminator({server: listener}); const terminator = createHttpTerminator({server: listener});
process.on('SIGINT', ()=> { process.on('SIGINT', () => {
void (async ()=> {
console.debug('Closing HTTPS server on signal'); console.debug('Closing HTTPS server on signal');
terminator.terminate().catch(e => { console.error(e); }); await terminator.terminate().catch(e => { console.error(e); });
console.debug('HTTPS server closed'); console.debug('HTTPS server closed');
})();
}); });
} }
@@ -554,10 +556,12 @@ function run() {
// Graceful shutdown when signalled // Graceful shutdown when signalled
const terminator = createHttpTerminator({server: listener}); const terminator = createHttpTerminator({server: listener});
process.on('SIGINT', ()=> { process.on('SIGINT', () => {
void (async () => {
console.debug('Closing HTTP server on signal'); console.debug('Closing HTTP server on signal');
terminator.terminate().catch(e => { console.error(e); }); await terminator.terminate().catch(e => { console.error(e); });
console.debug('HTTP server closed.'); console.debug('HTTP server closed.');return undefined;
})();
}); });
} }