diff options
author | Igor Klopov <igor@klopov.com> | 2016-02-13 06:35:40 -0500 |
---|---|---|
committer | Rod Vagg <rod@vagg.org> | 2016-02-16 14:58:52 +1100 |
commit | e9ac83ab35807c8d4b765743cc1782141aebc490 (patch) | |
tree | 0cf4167d29de6ede7a981bd26506f913c5237534 | |
parent | 954a4b4b5bb8a54b2e1d07105e4b2bb05a33e2ff (diff) | |
download | android-node-v8-e9ac83ab35807c8d4b765743cc1782141aebc490.tar.gz android-node-v8-e9ac83ab35807c8d4b765743cc1782141aebc490.tar.bz2 android-node-v8-e9ac83ab35807c8d4b765743cc1782141aebc490.zip |
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>
-rw-r--r-- | lib/cluster.js | 2 | ||||
-rw-r--r-- | test/parallel/test-cluster-disconnect-idle-worker.js | 5 |
2 files changed, 4 insertions, 3 deletions
diff --git a/lib/cluster.js b/lib/cluster.js index c8bf658d5b..4f7ca58170 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 e18c050044..c4a310a9d0 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), []); })); |