I work on an application with a REDIS data store. To maintain the data integrity I would like to cleanup the store on process shutdown.
I created a function handler and bind it (with process.on()) to signal events: uncaughtException, SIGINT, SIGTERM, SIGQUIT and it works well (CTRL+C, process killing, exception, ...).
But I've read that in certain conditions the process can exit directly without triggering the other signal events.
The problem in this particular case is that process.on('exit') handler can only process synchronous tasks.
I made different test to try to kill the process in different ways. And (except with SIGTERM on Windows) I wasn't able to identify the case where process.on('exit') is triggered directly without SIGINT, SIGTERM or other event firing.
So my question is (on Linux system), under what conditions the process can exit directly without firing on of this event: http://nodejs.org/api/all.html#all_signal_events ?
The process. exit() method is used to end the process which is running at the same time with an exit code in NodeJS. Parameter: This function accepts single parameter as mentioned above and described below: Code: It can be either 0 or 1.
SIGINT: Quit from keyboard (Ctrl + C). SIGQUIT: Quit from keyboard (Ctrl + ). It also produce a core dump file. SIGTERM: Quit from operating system (using kill command for example).
Node normally exits with code 0 when no more async operations are pending.
As of now, reading the documentation and doing some research, it seems there is only four way a node.js app exit:
process.exit()
, which is handled by process.on('exit')
process.on('UncaughtException')
It usually happen someone don t understand the error message from a uncaughtException, and mistakenly believe it is "something else" that killed node.js.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With