From: Sam Roberts Date: Wed, 18 Dec 2013 00:04:20 +0000 (-0800) Subject: cluster: do not synchronously emit 'setup' event X-Git-Tag: v0.11.10~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=876d3bd85aabe7fce71a025a89c6b3f6ddbf2053;p=platform%2Fupstream%2Fnodejs.git cluster: do not synchronously emit 'setup' event This is a problem present in both v0.10, and v0.11, where the 'setup' event is synchronously emitted by `cluster.setupMaster()`, a mostly harmless anti-pattern. --- diff --git a/lib/cluster.js b/lib/cluster.js index f75fda5..4f8fb8c 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -269,7 +269,9 @@ function masterInit() { process._debugProcess(cluster.workers[key].process.pid); }); - cluster.emit('setup'); + process.nextTick(function() { + cluster.emit('setup'); + }); }; var ids = 0; diff --git a/test/simple/test-cluster-setup-master.js b/test/simple/test-cluster-setup-master.js index b842228..d9f3879 100644 --- a/test/simple/test-cluster-setup-master.js +++ b/test/simple/test-cluster-setup-master.js @@ -39,6 +39,12 @@ if (cluster.isWorker) { var totalWorkers = 2; + // Setup master + cluster.setupMaster({ + args: ['custom argument'], + silent: true + }); + cluster.once('setup', function() { checks.setupEvent = true; @@ -51,12 +57,6 @@ if (cluster.isWorker) { } }); - // Setup master - cluster.setupMaster({ - args: ['custom argument'], - silent: true - }); - var correctIn = 0; cluster.on('online', function lisenter(worker) {