diff --git a/lib/cluster.js b/lib/cluster.js index c8bf658d5b32a8..4f7ca58170468f 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -342,7 +342,7 @@ function masterInit() { }); worker.on('message', (message, handle) => - this.emit('message', message, handle) + cluster.emit('message', message, handle) ); worker.process.once('exit', function(exitCode, signalCode) { diff --git a/test/parallel/test-cluster-disconnect-idle-worker.js b/test/parallel/test-cluster-disconnect-idle-worker.js index e18c05004467b7..c4a310a9d07268 100644 --- a/test/parallel/test-cluster-disconnect-idle-worker.js +++ b/test/parallel/test-cluster-disconnect-idle-worker.js @@ -2,10 +2,11 @@ var common = require('../common'); var assert = require('assert'); var cluster = require('cluster'); +var fork = cluster.fork; if (cluster.isMaster) { - cluster.fork(); - cluster.fork(); + fork(); // it is intentionally called `fork` instead of + fork(); // `cluster.fork` to test that `this` is not used cluster.disconnect(common.mustCall(function() { assert.deepEqual(Object.keys(cluster.workers), []); }));