From d5d428c4eed58de4cb087a7765187d224d0f188a Mon Sep 17 00:00:00 2001 From: muxator Date: Sat, 16 Feb 2019 00:14:39 +0100 Subject: [PATCH] windows: allow graceful shutdown on Windows, too Until Etherpad 1.7.5, process.on('SIGTERM') and process.on('SIGINT') were not hooked up under Windows, because old nodejs versions did not support them. This excluded the possibility of doing a graceful shutdown of the database connection under that platform. According to nodejs 6.x documentation, it is now safe to do so. This allows to gracefully close the DB connection when hitting CTRL+C under Windows, for example. Source: https://nodejs.org/docs/latest-v6.x/api/process.html#process_signal_events - SIGTERM is not supported on Windows, it can be listened on. - SIGINT from the terminal is supported on all platforms, and can usually be generated with +C (though this may be configurable). It is not generated when terminal raw mode is enabled. --- src/node/hooks/express/errorhandling.js | 32 ++++++++++++++++++------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/node/hooks/express/errorhandling.js b/src/node/hooks/express/errorhandling.js index c36595bdd..104a9c1bb 100644 --- a/src/node/hooks/express/errorhandling.js +++ b/src/node/hooks/express/errorhandling.js @@ -44,13 +44,27 @@ exports.expressCreateServer = function (hook_name, args, cb) { stats.meter('http500').mark() }) - //connect graceful shutdown with sigint and uncaughtexception - if(os.type().indexOf("Windows") == -1) { - //sigint is so far not working on windows - //https://github.com/joyent/node/issues/1553 - process.on('SIGINT', exports.gracefulShutdown); - // when running as PID1 (e.g. in docker container) - // allow graceful shutdown on SIGTERM c.f. #3265 - process.on('SIGTERM', exports.gracefulShutdown); - } + /* + * Connect graceful shutdown with sigint and uncaught exception + * + * Until Etherpad 1.7.5, process.on('SIGTERM') and process.on('SIGINT') were + * not hooked up under Windows, because old nodejs versions did not support + * them. + * + * According to nodejs 6.x documentation, it is now safe to do so. This + * allows to gracefully close the DB connection when hitting CTRL+C under + * Windows, for example. + * + * Source: https://nodejs.org/docs/latest-v6.x/api/process.html#process_signal_events + * + * - SIGTERM is not supported on Windows, it can be listened on. + * - SIGINT from the terminal is supported on all platforms, and can usually + * be generated with +C (though this may be configurable). It is not + * generated when terminal raw mode is enabled. + */ + process.on('SIGINT', exports.gracefulShutdown); + + // when running as PID1 (e.g. in docker container) + // allow graceful shutdown on SIGTERM c.f. #3265 + process.on('SIGTERM', exports.gracefulShutdown); }