From a91b1409636db20e931e14e1be03261f57ab3f7c Mon Sep 17 00:00:00 2001 From: cloudhead Date: Mon, 21 Feb 2011 19:31:01 -0500 Subject: [PATCH] fix process.on edge case with signal event When adding a listener for a signal event, removing it, and adding it back again, it triggers a condition with an undefined variable. --- src/node.js | 2 +- test/simple/test-signal-handler.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/node.js b/src/node.js index 789cb9b0e1..6b0aa6f53e 100644 --- a/src/node.js +++ b/src/node.js @@ -232,7 +232,7 @@ w.start(); } else if (this.listeners(type).length === 1) { - signalWatchers[event].start(); + signalWatchers[type].start(); } } diff --git a/test/simple/test-signal-handler.js b/test/simple/test-signal-handler.js index 906573a3ae..9866fd6693 100644 --- a/test/simple/test-signal-handler.js +++ b/test/simple/test-signal-handler.js @@ -6,6 +6,8 @@ console.log('process.pid: ' + process.pid); var first = 0, second = 0; +var sighup = false; + process.addListener('SIGUSR1', function() { console.log('Interrupted by SIGUSR1'); first += 1; @@ -28,8 +30,15 @@ setInterval(function() { } }, 1); +// Test addListener condition where a watcher for SIGNAL +// has been previously registered, and `process.listeners(SIGNAL).length === 1` +process.addListener('SIGHUP', function () {}); +process.removeAllListeners('SIGHUP'); +process.addListener('SIGHUP', function () { sighup = true }); +process.kill(process.pid, 'SIGHUP'); process.addListener('exit', function() { assert.equal(1, first); assert.equal(1, second); + assert.equal(true, sighup); });