diff options
Diffstat (limited to 'lib/cluster.js')
-rw-r--r-- | lib/cluster.js | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/cluster.js b/lib/cluster.js index 4e9ce2a8d..f75fda521 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -343,8 +343,8 @@ function masterInit() { signo = signo || 'SIGTERM'; var proc = this.process; if (proc.connected) { - proc.once('disconnect', proc.kill.bind(proc, signo)); - proc.disconnect(); + this.once('disconnect', proc.kill.bind(proc, signo)); + this.disconnect(); return; } proc.kill(signo); @@ -444,7 +444,13 @@ function workerInit() { worker.id = +process.env.NODE_UNIQUE_ID | 0; worker.state = 'online'; worker.process = process; - process.once('disconnect', process.exit.bind(null, 0)); + process.once('disconnect', function() { + if (!worker.suicide) { + // Unexpected disconnect, master exited, or some such nastiness, so + // worker exits immediately. + process.exit(0); + } + }); process.on('internalMessage', internal(worker, onmessage)); send({ act: 'online' }); function onmessage(message, handle) { @@ -554,6 +560,7 @@ function workerInit() { } Worker.prototype.disconnect = function() { + this.suicide = true; for (var key in handles) { var handle = handles[key]; delete handles[key]; @@ -563,6 +570,7 @@ function workerInit() { }; Worker.prototype.destroy = function() { + this.suicide = true; if (!process.connected) process.exit(0); var exit = process.exit.bind(null, 0); send({ act: 'suicide' }, exit); |