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 <cjihrig@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rod Vagg <rod@vagg.org>
  • Loading branch information
igorklopov authored and rvagg committed Feb 18, 2016
1 parent bbdf268 commit efd6f68
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 efd6f68

Please sign in to comment.