From dc1ffd0da6fcaa2b18bd6817ca3541264ebc8ce7 Mon Sep 17 00:00:00 2001 From: Alexis Campailla Date: Fri, 10 Jan 2014 05:27:48 -0800 Subject: [PATCH] test: race condition in test-cluster-disconnect The test was not waiting for all the worker-created sockets to be listening before calling cluster.disconnect(). As a result, the channels with the workers could get closed before all the socket handles had been passed to them, leading to various errors. --- test/simple/test-cluster-disconnect.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/simple/test-cluster-disconnect.js b/test/simple/test-cluster-disconnect.js index 8fbdb93385..797c17d767 100644 --- a/test/simple/test-cluster-disconnect.js +++ b/test/simple/test-cluster-disconnect.js @@ -35,6 +35,7 @@ if (cluster.isWorker) { }).listen(common.PORT + 1, '127.0.0.1'); } else if (cluster.isMaster) { + var servers = 2; // test a single TCP server var testConnection = function(port, cb) { @@ -52,7 +53,6 @@ if (cluster.isWorker) { // test both servers created in the cluster var testCluster = function(cb) { - var servers = 2; var done = 0; for (var i = 0, l = servers; i < l; i++) { @@ -76,7 +76,7 @@ if (cluster.isWorker) { var worker = cluster.fork(); worker.on('listening', function() { online += 1; - if (online === workers) { + if (online === workers * servers) { cb(); } });