Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Signal handlers are not removed/reverted with process.removeAllListeners([signal]) #25781

Closed
chjj opened this issue Jul 30, 2015 · 1 comment
Closed

Comments

@chjj
Copy link

chjj commented Jul 30, 2015

Handling signals in C has the advantage of calling the signal handler even if the main thread is blocked. Since javascript is limited in this area, I went for a workaround: unbind my SIGINT listener before doing my blocking operation. In doing so, I think I discovered a slight inconsistency.

process.on('SIGINT', function() {
  console.log('SIGINT');
  process.exit(0);
});
process.removeAllListeners('SIGINT');
console.log('start loop');
for (;;);

Even after removing the SIGINT listener, SIGINT still has no effect:

$ node test-signal.js
start loop
...
^C^C^C^C^C^C
...
^\
Quit (core dumped)
$

However, if I specifically remove the SIGINT listener, SIGINT reverts back to its original behavior:

var handle_sigint;
process.on('SIGINT', handle_sigint = function() {
  console.log('SIGINT');
  process.exit(0);
});
process.removeListener('SIGINT', handle_sigint);
console.log('start loop');
for (;;);
$ node test-signal.js
start loop
...
^C
$

Node Version: v0.12.7

@jasnell
Copy link
Member

jasnell commented Aug 3, 2015

Does not occur within io.js so possible backport

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants