possible fix for #2492

v1.18.x
barisusakli 10 years ago
parent c0bce71984
commit 7a5383748c

@ -21,7 +21,6 @@ var nconf = require('nconf'),
Loader = { Loader = {
timesStarted: 0, timesStarted: 0,
shutdown_queue: [],
js: { js: {
cache: undefined, cache: undefined,
map: undefined map: undefined
@ -86,12 +85,6 @@ Loader.addClusterEvents = function(callback) {
hash: Loader.css.hash hash: Loader.css.hash
}); });
} }
// Kill an instance in the shutdown queue
var workerToKill = Loader.shutdown_queue.pop();
if (workerToKill) {
cluster.workers[workerToKill].kill();
}
break; break;
case 'restart': case 'restart':
console.log('[cluster] Restarting...'); console.log('[cluster] Restarting...');
@ -269,9 +262,16 @@ function clusterWorkers() {
} }
Loader.restart = function(callback) { Loader.restart = function(callback) {
// Slate existing workers for termination -- welcome to death row. console.log('[cluster] closing server');
Loader.shutdown_queue = Loader.shutdown_queue.concat(Object.keys(cluster.workers));
killWorkers();
closeHandles();
server.close(function() {
console.log('[cluster] server closed');
Loader.start(); Loader.start();
});
}; };
Loader.reload = function() { Loader.reload = function() {
@ -283,10 +283,7 @@ Loader.reload = function() {
}; };
Loader.stop = function() { Loader.stop = function() {
Object.keys(cluster.workers).forEach(function(id) { killWorkers();
// Gracefully close workers
cluster.workers[id].kill();
});
// Clean up the pidfile // Clean up the pidfile
fs.unlinkSync(__dirname + '/pidfile'); fs.unlinkSync(__dirname + '/pidfile');
@ -294,6 +291,22 @@ Loader.stop = function() {
server.close(); server.close();
}; };
function killWorkers() {
Object.keys(cluster.workers).forEach(function(id) {
cluster.workers[id].kill();
});
}
function closeHandles() {
for(var h in handles) {
var handle = handles[h];
if (handle) {
h.close();
delete handles[handle];
}
}
}
Loader.notifyWorkers = function (msg) { Loader.notifyWorkers = function (msg) {
Object.keys(cluster.workers).forEach(function(id) { Object.keys(cluster.workers).forEach(function(id) {
cluster.workers[id].send(msg); cluster.workers[id].send(msg);

Loading…
Cancel
Save