fix process.on edge case with signal event
authorcloudhead <alexis@cloudhead.io>
Tue, 22 Feb 2011 00:31:01 +0000 (19:31 -0500)
committerRyan Dahl <ry@tinyclouds.org>
Wed, 23 Feb 2011 20:57:05 +0000 (12:57 -0800)
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
test/simple/test-signal-handler.js

index 789cb9b..6b0aa6f 100644 (file)
           w.start();
 
         } else if (this.listeners(type).length === 1) {
-          signalWatchers[event].start();
+          signalWatchers[type].start();
         }
       }
 
index 906573a..9866fd6 100644 (file)
@@ -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);
 });