cluster: send suicide message on disconnect
This commit causes Worker.prototype.disconnect() to send a suicide message to the cluster master. The function is also restructured to eliminate redundant code. Fixes: https://github.com/nodejs/node/issues/3238 PR-URL: https://github.com/nodejs/node/pull/3720 Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
b70dc67828
commit
f299d870dc
@ -654,26 +654,24 @@ function workerInit() {
|
|||||||
|
|
||||||
Worker.prototype.disconnect = function() {
|
Worker.prototype.disconnect = function() {
|
||||||
this.suicide = true;
|
this.suicide = true;
|
||||||
var waitingHandles = 0;
|
let waitingCount = 1;
|
||||||
|
|
||||||
function checkRemainingHandles() {
|
function checkWaitingCount() {
|
||||||
waitingHandles--;
|
waitingCount--;
|
||||||
if (waitingHandles === 0) {
|
if (waitingCount === 0) {
|
||||||
|
send({ act: 'suicide' });
|
||||||
process.disconnect();
|
process.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var key in handles) {
|
for (const key in handles) {
|
||||||
var handle = handles[key];
|
const handle = handles[key];
|
||||||
delete handles[key];
|
delete handles[key];
|
||||||
waitingHandles++;
|
waitingCount++;
|
||||||
handle.owner.close(checkRemainingHandles);
|
handle.owner.close(checkWaitingCount);
|
||||||
}
|
|
||||||
|
|
||||||
if (waitingHandles === 0) {
|
|
||||||
process.disconnect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkWaitingCount();
|
||||||
};
|
};
|
||||||
|
|
||||||
Worker.prototype.destroy = function() {
|
Worker.prototype.destroy = function() {
|
||||||
|
21
test/parallel/test-regress-GH-3238.js
Normal file
21
test/parallel/test-regress-GH-3238.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
'use strict';
|
||||||
|
const common = require('../common');
|
||||||
|
const assert = require('assert');
|
||||||
|
const cluster = require('cluster');
|
||||||
|
|
||||||
|
if (cluster.isMaster) {
|
||||||
|
const worker = cluster.fork();
|
||||||
|
let disconnected = false;
|
||||||
|
|
||||||
|
worker.on('disconnect', common.mustCall(function() {
|
||||||
|
assert.strictEqual(worker.suicide, true);
|
||||||
|
disconnected = true;
|
||||||
|
}));
|
||||||
|
|
||||||
|
worker.on('exit', common.mustCall(function() {
|
||||||
|
assert.strictEqual(worker.suicide, true);
|
||||||
|
assert.strictEqual(disconnected, true);
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
cluster.worker.disconnect();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user