Removing a signal handler from a process newListener
event handler doesn't work correctly
#51016
Labels
confirmed-bug
Issues with confirmed bugs.
events
Issues and PRs related to the events subsystem / EventEmitter.
process
Issues and PRs related to the process subsystem.
wontfix
Issues that will not be fixed.
Version
v21.3.0
Platform
Linux new-hope 6.5.0-2-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.5.6-1 (2023-10-07) x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
Consider this code (the idea is to set up a fallback SIGINT handler that will auto-remove if something else sets a handler):
Run
node sigTest.js
and press Ctrl+C.How often does it reproduce? Is there a required condition?
This happens regardless of whether the new listener is installed immediately or at a later point.
What is the expected behavior? Why is that the expected behavior?
Note the process shouldn't terminate. Adding the "real" handler should cause the "fallback" handler to be removed by the
newListener
event listener, leaving only the "real" handler as the SIGINT listener.What do you see instead?
Note the process terminates with exit code 1. Neither SIGINT handler runs.
Additional information
Wrapping
process.off
in asetImmediate
makes the code work as expected.The text was updated successfully, but these errors were encountered: