Browse Source

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.
v0.7.4-release
cloudhead 14 years ago
committed by Ryan Dahl
parent
commit
a91b140963
  1. 2
      src/node.js
  2. 9
      test/simple/test-signal-handler.js

2
src/node.js

@ -232,7 +232,7 @@
w.start(); w.start();
} else if (this.listeners(type).length === 1) { } else if (this.listeners(type).length === 1) {
signalWatchers[event].start(); signalWatchers[type].start();
} }
} }

9
test/simple/test-signal-handler.js

@ -6,6 +6,8 @@ console.log('process.pid: ' + process.pid);
var first = 0, var first = 0,
second = 0; second = 0;
var sighup = false;
process.addListener('SIGUSR1', function() { process.addListener('SIGUSR1', function() {
console.log('Interrupted by SIGUSR1'); console.log('Interrupted by SIGUSR1');
first += 1; first += 1;
@ -28,8 +30,15 @@ setInterval(function() {
} }
}, 1); }, 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() { process.addListener('exit', function() {
assert.equal(1, first); assert.equal(1, first);
assert.equal(1, second); assert.equal(1, second);
assert.equal(true, sighup);
}); });

Loading…
Cancel
Save