process: fix regression in unlistening signals
authorSam Roberts <sam@strongloop.com>
Tue, 30 Dec 2014 02:00:02 +0000 (18:00 -0800)
committerBen Noordhuis <info@bnoordhuis.nl>
Mon, 2 Feb 2015 20:59:57 +0000 (21:59 +0100)
commite9eb2ec1c491e82dda27fe07d0eaf14ff569351b
tree79db28a86200c02e69624bb798ec522023142820
parent233e333b183edeea6b740911061c7dc526078260
process: fix regression in unlistening signals

When the last signal listener is removed, the signal wrap should be
closed, restoring the default signal handling behaviour. This is done in
a (patched) process.removeListener(). However, events.removeAllListeners
has an optimization to avoid calling removeListener() if there are no
listeners for the 'removeListener' event, introduced in 56668f54d1. That
caused the following code to fail to terminate:

    process.stdin.resume();
    function listener() {};
    process.on('SIGINT', listener);
    process.removeAllListeners('SIGINT');
    process.kill(process.pid, 'SIGINT')

while the following will terminate:

    process.stdin.resume();
    function listener() {};
    process.on('SIGINT', listener);
    process.removeListener('SIGINT', listener);
    process.kill(process.pid, 'SIGINT')

Replace the method patching with use of the 'newListener' and
'removeListener' events, which will fire no matter which methods are
used to add or remove listeners.

PR-URL: https://github.com/iojs/io.js/pull/687
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
src/node.js
test/parallel/test-process-remove-all-signal-listeners.js [new file with mode: 0644]