Browse Source

cluster: dont rely on `this` in `fork`

PR-URL: https://github.com/nodejs/node/pull/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>
process-exit-stdio-flushing
Igor Klopov 9 years ago
committed by Rod Vagg
parent
commit
e9ac83ab35
  1. 2
      lib/cluster.js
  2. 5
      test/parallel/test-cluster-disconnect-idle-worker.js

2
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) {

5
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), []);
}));

Loading…
Cancel
Save