From 99a572d126e98bb52b5044fac630ebadbc0a4da6 Mon Sep 17 00:00:00 2001 From: Joni Shkurti Date: Mon, 16 Mar 2015 20:45:19 +0100 Subject: [PATCH 1/2] removeHandle on both 'exit' and 'disconnect' event [cluster.js][worker] Calls removeHandlesForWorker(worker) on both 'exit' and 'disconnect' event instead of just 'disconnect' because sometimes it happens that 'disconnect' event isn't emitted at all in which case some handles with be left and when all workers will be dead an exception raised "AssertionError: Resource leak detected". --- lib/cluster.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/cluster.js b/lib/cluster.js index e05de4568bc..bb956c0951a 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -360,6 +360,13 @@ function masterInit() { } worker.process.once('exit', function(exitCode, signalCode) { + /* + * Remove the handles associated with this + * worker a second time just in case 'disconnect' + * event isn't emitted. + */ + removeHandlesForWorker(worker); + /* * Remove the worker from the workers list only * if it has disconnected, otherwise we might From 33a4c12802bb12bf90a910e93e84dc9d44600a43 Mon Sep 17 00:00:00 2001 From: Joni Shkurti Date: Thu, 19 Mar 2015 16:15:36 +0100 Subject: [PATCH 2/2] Update cluster.js --- lib/cluster.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/cluster.js b/lib/cluster.js index bb956c0951a..5f0edcff095 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -365,7 +365,8 @@ function masterInit() { * worker a second time just in case 'disconnect' * event isn't emitted. */ - removeHandlesForWorker(worker); + if (worker.state != 'disconnected') + removeHandlesForWorker(worker); /* * Remove the worker from the workers list only