nodemon: Nodemon is not able to gracefully restart applications under Windows
nodemon -v: any- Operating system/terminal environment: Windows 10 Build 1809
Expected behaviour
Restarts while watching should send some kind of signal to the child processes so they can perform graceful restarts (and clean up resources) similar to listening to SIGINT signals.
Actual behaviour
On Windows this is not hapenning right now. On a file change the node process is forcefully killed without the possibility to perform cleanup tasks.
This is happening because nodemon is using a forced taskkill call on Windows:
After experimenting a bit I was able to come up with an experimental solution which has its flaws. Replacing the exec call with child.send("SIGUSR2") for IPC messaging allowed me to add a process.on("message", (message) => { if (message === "SIGUSR2") { process.kill(process.pid); } }) which was invoked properly, however it MUST end in process.kill(process.pid) otherwise nodemon will hang. Surprisingly enough this worked in my short tests and most likely will be my custom solution for this.
One big caveat is of course that the child process MUST kill itself properly. Furthermore I can’t predict what will happen on long-running cleanup processes.
I’d like to discuss whether you’d be interested in having such an experimental SIGUSR2-signal (which is not an actual signal but an IPC message) for Windows as an optional feature using another config option that replaces the hard taskkill. I can create a PR if you’re not going to implement it yourself.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 16 (2 by maintainers)
+1
+1 Please
+1 for this issue.
My current workaround is to use
nodemonthrough theWindows Subsystem for Linux. Works with the--inspectflag too.