From 3e8c3e5789aabc320462cc25c238ece77c4eea0f Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 22 Dec 2020 00:41:13 -0500 Subject: [PATCH] express: Factor out common server shutdown logic Also log when the HTTP server is about to be closed and when it is done closing. --- src/node/hooks/express.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/node/hooks/express.js b/src/node/hooks/express.js index d520ee6eb..50cb8657e 100644 --- a/src/node/hooks/express.js +++ b/src/node/hooks/express.js @@ -17,6 +17,14 @@ let serverName; exports.server = null; +const closeServer = async () => { + if (exports.server == null) return; + logger.info('Closing HTTP server...'); + await util.promisify(exports.server.close.bind(exports.server))(); + exports.server = null; + logger.info('HTTP server closed'); +}; + exports.createServer = async () => { console.log('Report bugs at https://github.com/ether/etherpad-lite/issues'); @@ -50,10 +58,7 @@ exports.createServer = async () => { }; exports.restartServer = async () => { - if (exports.server) { - console.log('Restarting express server'); - await util.promisify(exports.server.close).bind(exports.server)(); - } + await closeServer(); const app = express(); // New syntax for express v3 @@ -181,6 +186,5 @@ exports.restartServer = async () => { }; exports.shutdown = async (hookName, context) => { - if (!exports.server) return; - await util.promisify(exports.server.close).bind(exports.server)(); + await closeServer(); };