Skip to content

Commit 46d09e3

Browse files
igorklopovMyles Borins
authored and
Myles Borins
committed
cluster: dont rely on this in fork
PR-URL: #5216 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Brian White <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rod Vagg <[email protected]>
1 parent 0db1eaf commit 46d09e3

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/cluster.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ function masterInit() {
342342
});
343343

344344
worker.on('message', (message, handle) =>
345-
this.emit('message', message, handle)
345+
cluster.emit('message', message, handle)
346346
);
347347

348348
worker.process.once('exit', function(exitCode, signalCode) {

test/parallel/test-cluster-disconnect-idle-worker.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
var common = require('../common');
33
var assert = require('assert');
44
var cluster = require('cluster');
5+
var fork = cluster.fork;
56

67
if (cluster.isMaster) {
7-
cluster.fork();
8-
cluster.fork();
8+
fork(); // it is intentionally called `fork` instead of
9+
fork(); // `cluster.fork` to test that `this` is not used
910
cluster.disconnect(common.mustCall(function() {
1011
assert.deepEqual(Object.keys(cluster.workers), []);
1112
}));

0 commit comments

Comments
 (0)