You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
there should definitely be a One True Way to tell if node is about to exit. (as its worth noting that receiving some of those events does not guarantee that node will exit in every situation) i think we should just streamline {things in c++ that make node stop running} to always go through a call to js if possible.
Reacted by pravdomil, Horaddrim, Nicolas Gomez, Jeremy Kelly, Ayush Singh and Mvb1122
Changing the behavior of 'exit' could cause breakage. I would prefer a new event to avoid such issues. However there is a problem if you'd be using such a new event for "cleanup" because you wouldn't be able to do anything asynchronous, unless you additionally have a 'beforeShutdown' event or something similar.
There are reasons why this isn’t the default for process.on('exit') – libuv’s signal handling is asynchronous (as opposed to synchronous OS-enforced exit by default), so adding listeners for these events would avoid mean that we can’t break out of e.g. infinite loops without significantly more complex signal handling code.
And maybe be confusing one unique event, because if I listen to the event uncaughtException, maybe I use a different handler to a SIGTERM event. And @addaleax is extremely right to point that, maybe the assertion of this event can break some applications if you really depends on the ending of some other process.
It is technically possible to make this happen but, as Anna mentions, doing it properly significantly complicates signal handling; think signal masks, watchdog threads and asynchronous termination exceptions. We'd also need to carefully audit the code base for termination exception safety.
I'm going to say the cost/benefit ratio currently isn't worth it and close this out. If someone volunteers, we can reconsider. And who knows, maybe it'll fall out as a side effect of worker-ifying core someday.
Activity
Fishrock123 commentedon May 17, 2018
There's an npm module that does this, right? Does it need to be in core? Would it be that much more helpful?
devsnek commentedon May 17, 2018
there should definitely be a One True Way to tell if node is about to exit. (as its worth noting that receiving some of those events does not guarantee that node will exit in every situation) i think we should just streamline {things in c++ that make node stop running} to always go through a call to js if possible.
jasnell commentedon May 17, 2018
My preference would be to make
process.on('exit')always run in every case.mscdex commentedon May 17, 2018
Changing the behavior of
'exit'could cause breakage. I would prefer a new event to avoid such issues. However there is a problem if you'd be using such a new event for "cleanup" because you wouldn't be able to do anything asynchronous, unless you additionally have a'beforeShutdown'event or something similar.addaleax commentedon May 17, 2018
There are reasons why this isn’t the default for
process.on('exit')– libuv’s signal handling is asynchronous (as opposed to synchronous OS-enforced exit by default), so adding listeners for these events would avoid mean that we can’t break out of e.g. infinite loops without significantly more complex signal handling code.Horaddrim commentedon May 21, 2018
And maybe be confusing one unique event, because if I listen to the event
uncaughtException, maybe I use a different handler to aSIGTERMevent. And @addaleax is extremely right to point that, maybe the assertion of this event can break some applications if you really depends on the ending of some other process.gireeshpunathil commentedon Dec 1, 2018
is there an actionable on this issue? Is there any forward path justified / identified?
bnoordhuis commentedon Dec 6, 2018
It is technically possible to make this happen but, as Anna mentions, doing it properly significantly complicates signal handling; think signal masks, watchdog threads and asynchronous termination exceptions. We'd also need to carefully audit the code base for termination exception safety.
I'm going to say the cost/benefit ratio currently isn't worth it and close this out. If someone volunteers, we can reconsider. And who knows, maybe it'll fall out as a side effect of worker-ifying core someday.