mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
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.
This commit is contained in:
parent
0248c87ec7
commit
a91b140963
@ -232,7 +232,7 @@
|
||||
w.start();
|
||||
|
||||
} else if (this.listeners(type).length === 1) {
|
||||
signalWatchers[event].start();
|
||||
signalWatchers[type].start();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user