Skip to content

Commit 8cba3b2

Browse files
cjihrigMyles Borins
authored and
Myles Borins
committedJul 14, 2016
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: #6561 PR-URL: #6902 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]>
1 parent c5051ef commit 8cba3b2

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
 

‎lib/cluster.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ function internal(worker, cb) {
733733
return function(message, handle) {
734734
if (message.cmd !== 'NODE_CLUSTER') return;
735735
var fn = cb;
736-
if (message.ack !== undefined) {
736+
if (message.ack !== undefined && callbacks[message.ack] !== undefined) {
737737
fn = callbacks[message.ack];
738738
delete callbacks[message.ack];
739739
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const cluster = require('cluster');
5+
6+
if (cluster.isMaster) {
7+
const worker = cluster.fork();
8+
9+
worker.on('exit', common.mustCall((code, signal) => {
10+
assert.strictEqual(code, 0);
11+
assert.strictEqual(signal, null);
12+
}));
13+
14+
worker.on('online', () => {
15+
worker.send({
16+
cmd: 'NODE_CLUSTER',
17+
ack: -1
18+
}, () => {
19+
worker.disconnect();
20+
});
21+
});
22+
}

0 commit comments

Comments
 (0)
Please sign in to comment.