remy / nodemon

Monitor for any changes in your node.js application and automatically restart the server - perfect for development
http://nodemon.io/
MIT License
26.34k stars 1.74k forks source link

Nodemon not respecting graceful shutdown #2238

Open bugs181 opened 6 days ago

bugs181 commented 6 days ago

Expected behaviour

When running the code directly via node index.js the result is as expected

$ node index.js

[scanner] Resuming work
Job 970923B9DDFA472AF33E73F9E00CB8781004360D stalled and will be reprocessed
^CExiting due to signal SIGINT
Shutting down
[service] Disconnecting
[service] TODO: cleanup
Stopping workers
stopWorker()
here
Finished clean shutdown

Actual behaviour

When running via nodemon index.js or nodemon --signal SIGTERM the process is killed too early.

$ nodemon --signal SIGTERM

[nodemon] 3.1.7
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,cjs,json
[nodemon] starting `node index.js`
[scanner] Resuming work
Job 970923B9DDFA472AF33E73F9E00CB8781004360D stalled and will be reprocessed
^CExiting due to signal SIGINT
Shutting down
[service] Disconnecting
[service] TODO: cleanup
Stopping workers
stopWorker()

Steps to reproduce

I am using async-cleanup to listen for the events. This doesn't appear to do anything special. It hooks into the following signals, then awaits the result of user-code gracefulShutdown before sending a process.exit(0)

Events listened to:

const listenedSignals = [
  "SIGBREAK", // Ctrl-Break on Windows
  "SIGHUP", // Parent terminal closed
  "SIGINT", // Terminal interrupt, usually by Ctrl-C
  "SIGTERM", // Graceful termination
  "SIGUSR2", // Used by Nodemon
] as const;

It appears that nodemon is not respecting the SIGINT (CTRL + C) signal and is killing the process early.