From 29ba5083d12a8d3fd4c546c9170efdf166dfd76d Mon Sep 17 00:00:00 2001 From: Keith Gable Date: Thu, 13 Jul 2017 13:20:23 -0700 Subject: [PATCH] Also clear the shutdown timer in GracefulServer, even though we're process.exit(0)'ing immediately afterwards. Leaking resources is no bueno. --- lib/graceful-server.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/graceful-server.js b/lib/graceful-server.js index 701ddc5..1c66ef0 100644 --- a/lib/graceful-server.js +++ b/lib/graceful-server.js @@ -10,6 +10,7 @@ var GracefulServer = function(options) { this.log = options.log || console.log; this.shutdownTimeout = options.shutdownTimeout || 5000; + this._shutdownTimer = null; // Solution got from: https://github.com/nodejs/node-v0.x-archive/issues/9066#issuecomment-124210576 @@ -66,13 +67,14 @@ GracefulServer.prototype.shutdown = function() { var that = this; - setTimeout(function() { + this._shutdownTimer = setTimeout(function() { that.log('pid:' + process.pid + ' graceful shutdown: timeout, force exit.'); process.exit(0); }, this.shutdownTimeout); this.server.close(function() { that.log('pid:' + process.pid + ' graceful shutdown: done.'); + if (that._shutdownTimer) clearTimeout(that._shutdownTimer); process.exit(0); });