-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nodemon does not wait for process exit before restarting a new process, when Node's --inspect is used #2056
Comments
So, you've got a number of variables going on here. There's a long answer here, but the problem is all the moving parts - plus I'm on mac which doesn't replicate what you're seeing. It mostly boils down to your script trying to handle the exit process. If you change this for a simple server, do you see the same issue?
|
This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up. |
I ran into this issue for quite some time and, while I'm sure there's some helpful documentation existing somewhere, it didn't click for me until I started reading the code. I'm not sure if my issue is the same as yours, but hopefully my trials and tribulations may benefit you. TL;DR: IN MY CASE During my tests, the existence of The interaction of processes certainly isn't my expertise, so forgive me for "stating the obvious" or having an unnecessarily "hacky" approach to solving the problem. There's probably a more simple way to do this. Here's what worked for me, though: I run my Node app as a Docker container using Docker Compose. As many of the guides online suggest, my initial Docker config used docker-compose.ymlapi:
image: "node:16"
user: "node"
working_dir: /home/node/app
env_file:
- ../global.env
environment:
NODE_ENV: production
NETWORK_ACCESS: "internal"
volumes:
- ./assets:/home/node/assets
- ./conf:/home/node/conf
- ./api:/home/node/app
- ./lib:/home/node/lib
ports:
- "9230:9230"
command:
- "node_modules/.bin/nodemon"
- "./dist/index.js"
restart: unless-stopped package.json{
"restartable": "false",
"delay": 2500,
"verbose": true,
"watch": [".env", "package.json", "dist"],
"watchOptions": {},
"env": {
"NODE_OPTIONS": "--inspect-brk=0.0.0.0:9230"
},
"ext": "js,json"
} Note: I'm running node in a container that has multiple layers of security between it and the public internet. I wouldn't recommend using With this setup, not only does nodemon now properly wait on my node app's exit, but I also gained the ability to send kill signals ( Hope this helps. |
I ran into the same issue with Nodemon 2.0.19. When i saved the changes, it gives me an error "Error: listen EADDRINUSE: address already in use". Then I found that nodemon generates files called localhost: (in my case I am using express as my backend router) for each process with different port number, which are backend router is listening. So I just deleted these files and then I restarted nodemon and it worked fine. |
I'm having the exact same issue with the --inspect flag, and it started out of nowhere a few days ago.
package.json script: Starting server:
Whenever I update any file:
As a result, my codebase is not updated until I shut the server down and restart it manually. @edit:
|
@R4JxF60 just as clarification - nodemon doesn't create any files beyond the config file created in @Lipemenezes that If I can find the time, I'll add this to the FAQ (though not super sure how many people look at it - I'll have to fix that somehow). Otherwise you're welcome to send a PR to add this to the FAQ, I'm sure people will find it useful. |
This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up. |
Automatically closing this issue due to lack of activity |
Definitely not a fix but for others who are still struggling to get it to work, you can also add a sleep to the configuration which gives it time to actually exit before starting up again
Not the most reliable way, but its fixed majority of the issues that I've had with this race condition. |
Executing a sleep on the restart event doesn't seem to do the trick. It looks like the restart hook doesn't block the actual restart. However, I was able to get a servicable work around by prefixing the --exec with a E.g.,
|
nodemon -v
: 2.0.19nodemon --inspect=9231 test.js
Normal behavior
According to #1508, nodemon past version 2.0.0 waits for the process and child processes to exit before attempting to restart the process, after a file change or by entering
rs
in the console.I have a graceful shutdown asynchronous routine that
process.exit()
when it's done, but nodemon starts a process before the process actually exits.Here is a repro where things work correclty -- if running without
--inspect
:test.js
Output shows it's fine, nodemon waits (
rs
was used):(However, why do I receive SIGUSR2 two times? Had to use process.on instead of process.once because of that, the script was terminated the second time).
pstree:
Actual behavior
When running with
--inspect
, nodemon can't wait for the process to exit:test.js: unchanged
Output shows mingled output of the two processes running at the same time when restarting:
(Also, this time we get SIGUSR2 only once ??)
pstree (a new child process appeared):
It would be nice if this use case could be supported. Having a debugger server always ready to listen is quite practical.
I don't know if it's possible, because it seems that the debugger process wrapping the script is kinda killed by SIGUSR2, which triggers the restart immediately, while the script process is still running. But then I don't know why
Starting inspector on 127.0.0.1:9231 failed: address already in use
is thrown by the inspector from times to times.Using nodemon flag
--signal SIGINT
indeed shows a different behavior but then the script doesn't receive it, only the inspector. Which is not the same as when I press CTRL+C for some reason.Also, I would like to know why SIGUSR2 is sent 2 times (in a short interval) in the normal case.
(Edit: just made a test with SIGINT instead of SIGUSR2. This time I receive it three times instead of one. Running with just
node test.js
does not show this behavior)The text was updated successfully, but these errors were encountered: