Created
February 22, 2011 00:35
-
-
Save cloudhead/838008 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 13f75861414b07aa44345c549a04e0850a3cc2cf Mon Sep 17 00:00:00 2001 | |
From: cloudhead <alexis@cloudhead.io> | |
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 deletions(-) | |
diff --git a/src/node.js b/src/node.js | |
index 789cb9b..6b0aa6f 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 906573a..9866fd6 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); | |
}); | |
-- | |
1.7.4.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment