Skip to content

Commit

Permalink
cluster: dont rely on this in fork
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
igorklopov authored and Myles Borins committed Mar 1, 2016
1 parent 78d6488 commit 81d4127
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-cluster-disconnect-idle-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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), []);
}));
Expand Down

0 comments on commit 81d4127

Please sign in to comment.