From 46e2f4e22cc469beb2408e6857a6d5711a4d6b2a Mon Sep 17 00:00:00 2001 From: "Mark H. Wood" Date: Tue, 22 Aug 2023 15:46:55 -0400 Subject: [PATCH] Properly await termination. (cherry picked from commit 4449737aed9b96c13ba6a34e2ff72feb1aaebe92) --- server.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/server.ts b/server.ts index 0fbec1beae..baa7321503 100644 --- a/server.ts +++ b/server.ts @@ -536,10 +536,12 @@ function createHttpsServer(keys) { // Graceful shutdown when signalled const terminator = createHttpTerminator({server: listener}); - process.on('SIGINT', ()=> { - console.debug('Closing HTTPS server on signal'); - terminator.terminate().catch(e => { console.error(e); }); - console.debug('HTTPS server closed'); + process.on('SIGINT', () => { + void (async ()=> { + console.debug('Closing HTTPS server on signal'); + await terminator.terminate().catch(e => { console.error(e); }); + console.debug('HTTPS server closed'); + })(); }); } @@ -555,10 +557,12 @@ function run() { // Graceful shutdown when signalled const terminator = createHttpTerminator({server: listener}); - process.on('SIGINT', ()=> { - console.debug('Closing HTTP server on signal'); - terminator.terminate().catch(e => { console.error(e); }); - console.debug('HTTP server closed.'); + process.on('SIGINT', () => { + void (async () => { + console.debug('Closing HTTP server on signal'); + await terminator.terminate().catch(e => { console.error(e); }); + console.debug('HTTP server closed.');return undefined; + })(); }); }