diff --git a/CHANGELOG.md b/CHANGELOG.md index 64d3d35..00ebda8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +0.4.1 / 2018-01-15 +================== + + * Name anonymous functions for call stack clarity + 0.4.0 / 2017-03-19 ================== diff --git a/lib/graceful-exit.js b/lib/graceful-exit.js index 3037e69..f930348 100644 --- a/lib/graceful-exit.js +++ b/lib/graceful-exit.js @@ -6,7 +6,7 @@ var sockets = []; * Keep track of open connections so we can forcibly close sockets when the suicide timeout elapses * @param server HTTP server */ -exports.init = function (server) { +exports.init = function init(server) { server.on('connection', function (socket) { sockets.push(socket); @@ -16,7 +16,7 @@ exports.init = function (server) { }); }; -exports.gracefulExitHandler = function(app, server, _options) { +exports.gracefulExitHandler = function gracefulExitHandler(app, server, _options) { // Get the options set up if (!_options) { _options = {}; @@ -45,13 +45,14 @@ exports.gracefulExitHandler = function(app, server, _options) { if (options.callback) { if (_.isFunction(options.callback)) { options.callback(code); + options.callback = false; // prevent 2nd call } else { logger("Registered callback is not a function"); } } if (options.exitProcess) { // leave a bit of time to write logs, callback to complete, etc - setTimeout(function() { + setTimeout(function exitProcess() { process.exit(1); }, options.exitDelay); } @@ -71,7 +72,7 @@ exports.gracefulExitHandler = function(app, server, _options) { // Everything was closed successfully, mission accomplished! connectionsClosed = true; - logger('All connections closed gracefully'); + logger('No longer accepting connections'); exit(0); clearTimeout(suicideTimeout); @@ -108,7 +109,7 @@ exports.gracefulExitHandler = function(app, server, _options) { // If after an acceptable time limit is reached and we still have some // connections lingering around for some reason, just die... we tried to // be graceful, but failed. - suicideTimeout = setTimeout(function() { + suicideTimeout = setTimeout(function suicideHandler() { if (connectionsClosed) { // this condition should never occur, see server.close() above // user callback, if any, has already been called @@ -131,14 +132,14 @@ exports.gracefulExitHandler = function(app, server, _options) { }, options.suicideTimeout); }; -exports.middleware = function(app) { +exports.middleware = function middleware(app) { // This flag is used to tell the middleware we create that the server wants - // to stop, so we do not allow anymore connections. This is done for all new + // to stop, so we do not allow any more connections. This is done for all new // connections for us by Node, but we need to handle the connections that are // using the Keep-Alive header to stay on. app.set('graceful_exit', false); - return function(req, res, next) { + return function checkGracefulExit(req, res, next) { // Sorry Keep-Alive connections, but we need to part ways if (app.settings.graceful_exit === true) { req.connection.setTimeout(1); diff --git a/package.json b/package.json index fdc1cfc..8c7ced8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "express-graceful-exit", - "version": "0.4.0", + "version": "0.4.1", "description": "Allow graceful exits for express apps, supporting zero downtime deploys", "keywords": [ "express",