From 17d7916fe93c32022712892da81d72d4a99444a7 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 28 Nov 2014 20:00:41 -0500 Subject: [PATCH] check if worker exists --- loader.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/loader.js b/loader.js index 5f38d72fa7..28b34f0bbc 100644 --- a/loader.js +++ b/loader.js @@ -193,12 +193,18 @@ Loader.start = function(callback) { server = net.createServer(function(connection) { // remove this once node 0.12.x ships, see https://github.com/elad/node-cluster-socket.io/issues/4 connection._handle.readStop(); - handles[handleIndex] = connection._handle; - var workers = clusterWorkers(); + var workers = clusterWorkers(); var worker = workers[workerIndex(connection.remoteAddress, numProcs)]; - worker.send({action: 'sticky-session:connection', handleIndex: handleIndex}, connection); - handleIndex ++; + + if (worker) { + handles[handleIndex] = connection._handle; + + worker.send({action: 'sticky-session:connection', handleIndex: handleIndex}, connection); + handleIndex ++; + } else { + console.log('Cant find worker! Worker count : ' + workers.length); + } }).listen(port);