New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set graceful shutdown off by default #1927
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
'use strict'; | ||
// smtp network server | ||
|
||
// var log = require('why-is-node-running'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW I left this in but commented because it makes it easy to debug any kind of "won't quit" issues in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Says the guy that use to be adamantly opposed to such a thing. ;-) Welcome to the dark side. ;-) |
||
var net = require('./tls_socket'); | ||
var conn = require('./connection'); | ||
var outbound = require('./outbound'); | ||
|
@@ -27,6 +28,7 @@ Server.load_smtp_ini = function () { | |
Server.cfg = Server.config.get('smtp.ini', { | ||
booleans: [ | ||
'-main.daemonize', | ||
'-main.graceful_shutdown', | ||
], | ||
}, function () { | ||
Server.load_smtp_ini(); | ||
|
@@ -97,26 +99,33 @@ Server.gracefulRestart = function () { | |
Server._graceful(); | ||
} | ||
|
||
Server.performShutdown = function () { | ||
if (Server.cfg.main.graceful_shutdown) { | ||
return Server.gracefulShutdown(); | ||
} | ||
logger.loginfo("Shutting down."); | ||
process.exit(0); | ||
} | ||
|
||
Server.gracefulShutdown = function () { | ||
logger.loginfo('Shutting down listeners'); | ||
Server.listeners.forEach(function (server) { | ||
server.close(); | ||
}); | ||
Server._graceful(function () { | ||
// log(); | ||
logger.loginfo("Failed to shutdown naturally. Exiting."); | ||
process.exit(0); | ||
}); | ||
} | ||
|
||
Server._graceful = function (shutdown) { | ||
if (!Server.cluster) { | ||
if (shutdown) { | ||
['outbound', 'cfreader', 'plugins'].forEach(function (module) { | ||
process.emit('message', {event: module + '.shutdown'}); | ||
}); | ||
var t = setTimeout(shutdown, Server.cfg.main.force_shutdown_timeout * 1000); | ||
return t.unref(); | ||
} | ||
if (!Server.cluster && shutdown) { | ||
['outbound', 'cfreader', 'plugins'].forEach(function (module) { | ||
process.emit('message', {event: module + '.shutdown'}); | ||
}); | ||
var t = setTimeout(shutdown, Server.cfg.main.force_shutdown_timeout * 1000); | ||
return t.unref(); | ||
} | ||
|
||
if (gracefull_in_progress) { | ||
|
@@ -129,10 +138,13 @@ Server._graceful = function (shutdown) { | |
var disconnect_timeout = 30; | ||
var exit_timeout = 30; | ||
cluster.removeAllListeners('exit'); | ||
// only reload one worker at a time | ||
// otherwise, we'll have a time when no connection handlers are running | ||
// we reload using eachLimit where limit = num_workers - 1 | ||
// this kills all-but-one workers in parallel, leaving one running | ||
// for new connections, and then restarts that one last worker. | ||
var worker_ids = Object.keys(cluster.workers); | ||
async.eachSeries(worker_ids, function (id, cb) { | ||
var limit = worker_ids.length - 1; | ||
if (limit < 2) limit = 1; | ||
async.eachLimit(worker_ids, limit, function (id, cb) { | ||
logger.lognotice("Killing node: " + id); | ||
var worker = cluster.workers[id]; | ||
['outbound', 'cfreader', 'plugins'].forEach(function (module) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,6 +137,10 @@ pluggableStream.prototype.setKeepAlive = function (bool) { | |
pluggableStream.prototype.setNoDelay = function (/* true||false */) { | ||
}; | ||
|
||
pluggableStream.prototype.unref = function () { | ||
return this.targetsocket.unref(); | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this in case we need to unref a socket in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this ever get called while targetsocket is undefined? |
||
|
||
pluggableStream.prototype.setTimeout = function (timeout) { | ||
this._timeout = timeout; | ||
return this.targetsocket.setTimeout(timeout); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW how come we now have a haraka-config package and this file is still in Haraka?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since moving config into a module (so npm plugins could depend on it) I've been moving more and more stuff to depend on haraka-config, with the eventual plan to deprecate the build-in conifg.js and configfile.js. We're a ways down that road and I don't recall right now what's left to do.