From 3a4d6ad2059df2dd3d0f986b46d3d4f741c2de43 Mon Sep 17 00:00:00 2001 From: Igor Klopov Date: Sat, 13 Feb 2016 06:35:40 -0500 Subject: [PATCH] cluster: dont rely on `this` in `fork` PR-URL: https://github.com/nodejs/node/pull/5216 Reviewed-By: Colin Ihrig Reviewed-By: Brian White Reviewed-By: James M Snell Reviewed-By: Rod Vagg --- lib/cluster.js | 2 +- 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), []); }));