mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
cluster: guard against undefined message handlers
cluster's internal message handling includes a cache of callback functions. Once the message for that callback is received, it is removed from the cache. If, for any reason, the same message ID is processed twice, the callback will be missing from the cache and cluster will try to call undefined as a function. This commit guards against this scenario. Refs: https://github.com/nodejs/node/issues/6561 PR-URL: https://github.com/nodejs/node/pull/6902 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
This commit is contained in:
1 parent
9140b97848
commit
33c7b45378
2 files changed
+23
-1
No files matched your search
+1
-1
@@ -749,7 +749,7 @@ function internal(worker, cb) {
|
||||
return function(message, handle) {
|
||||
if (message.cmd !== 'NODE_CLUSTER') return;
|
||||
var fn = cb;
|
||||
if (message.ack !== undefined) {
|
||||
if (message.ack !== undefined && callbacks[message.ack] !== undefined) {
|
||||
fn = callbacks[message.ack];
|
||||
delete callbacks[message.ack];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const cluster = require('cluster');
|
||||
|
||||
if (cluster.isMaster) {
|
||||
const worker = cluster.fork();
|
||||
|
||||
worker.on('exit', common.mustCall((code, signal) => {
|
||||
assert.strictEqual(code, 0);
|
||||
assert.strictEqual(signal, null);
|
||||
}));
|
||||
|
||||
worker.on('online', () => {
|
||||
worker.send({
|
||||
cmd: 'NODE_CLUSTER',
|
||||
ack: -1
|
||||
}, () => {
|
||||
worker.disconnect();
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user