Skip to content

Commit

Permalink
Also clear the shutdown timer in GracefulServer, even though we're pr…
Browse files Browse the repository at this point in the history
…ocess.exit(0)'ing immediately afterwards. Leaking resources is no bueno.
  • Loading branch information
ziggythehamster committed Jul 13, 2017
1 parent 11b433f commit 29ba508
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/graceful-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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);
});

Expand Down

0 comments on commit 29ba508

Please sign in to comment.