nodemon -v: 1.17.4node -v: v10.1.0nodemon --expose-gc --inspect=0.0.0.0:9228 --legacy-watch --delay 250ms --watch webpack.config.js node_modules/.bin/webpack-dev-server --mode development --host 0.0.0.0 --port 80When a file has changed, it should restart the node application, with the following steps "stop the current application; start the a new instance of the application"
It's starting the application before the previous instance finish to stop, what makes it to fail and display the following error:
[nodemon] starting `node --expose-gc --inspect=0.0.0.0:9228 node_modules/.bin/webpack-dev-server --mode development --host 0.0.0.0 --port 80 src/index.js`
Starting inspector on 0.0.0.0:9228 failed: address already in use
[nodemon] app crashed - waiting for file changes before starting...
If any the watched file get's changed, it restart again and it work since it will be enough time to stop the application instance.
Start a simple project with webpack-dev-server, babel and react, then add a dummy src/index.js that initialize react to make the process be a bit slower for webpack-dev-server.
Start the nodemon using the command provided.
execute: touch webpack.config.js it might fail if your computer isn't fast enough to stop the instance before start the next.
Listen for the PID to be dead before start a new instance using a timeout or interval when --inspector flag is added to nodemon, to be sure that all resources are available before starting a new instance.
If applicable, please append the --dump flag on your command and include the output here ensuring to remove any sensitive/personal details or tokens.
Please provide a git repo to replicate from. I'm not going to guess at the package config (and I've used inspect with nodemon with success, so the config is what I'm after).
Also, if you have a suggestion, best to provide a PR with a test showing it works, that would be absolutely 馃憤
I'll think how can I create an isolated project that can be used to reproduce that, but it seems to be very challenging, here I can reproduce inside docker containers since I can reduce the resources available from my computer to execute the app.
Maybe you'll be able to debug your project directly (and I suspect there's something special about the project that's causing the issue, but I know others have seen something vaguely similar, but never able to replicate).
You can also use DEBUG=nodemon* to get more info out, and if required, I can do some debug release to help get into what's causing the issue (I suspect around thekill method in the run.js file)
I'm also seeing this error randomly, while using nodemon inside a Docker container. The error is completely random, I'm not able to create a repro scenario.
I tried adding a DEBUG=nodemon* env inside the container, then I caused a few restarts until I received an error.
This is the log of a successful restart:
my_container_1 | Thu, 24 May 2018 15:30:32 GMT nodemon bus emit: restart
my_container_1 | [nodemon] restarting due to changes...
my_container_1 | Thu, 24 May 2018 15:30:33 GMT nodemon bus.emit(exit) via SIGUSR2
my_container_1 | [nodemon] starting `node --inspect=0.0.0.0:7005 src/index.js`
my_container_1 | Thu, 24 May 2018 15:30:33 GMT nodemon bus emit: exit
my_container_1 | Thu, 24 May 2018 15:30:33 GMT nodemon spawning node --inspect=0.0.0.0:7005 src/index.js
my_container_1 | Thu, 24 May 2018 15:30:33 GMT nodemon bus new listener: exit (1)
my_container_1 | Thu, 24 May 2018 15:30:33 GMT nodemon start watch on: ./,../shared/
my_container_1 | Thu, 24 May 2018 15:30:33 GMT nodemon:watch early exit on watch, still watching (2)
my_container_1 | Debugger listening on port 7005.
my_container_1 | Warning: This is an experimental feature and could change at any time.
my_container_1 | To start debugging, open the following URL in Chrome:
my_container_1 | chrome-devtools://devtools/remote/serve_file/@60cd6e859b9f557d2...
This is the log of the failure:
my_container_1 | [nodemon] restarting due to changes...
my_container_1 | Thu, 24 May 2018 15:30:47 GMT nodemon bus emit: restart
my_container_1 | Thu, 24 May 2018 15:30:47 GMT nodemon bus.emit(exit) via SIGUSR2
my_container_1 | Thu, 24 May 2018 15:30:47 GMT nodemon bus emit: exit
my_container_1 | [nodemon] starting `node --inspect=0.0.0.0:7005 src/index.js`
my_container_1 | Thu, 24 May 2018 15:30:47 GMT nodemon spawning node --inspect=0.0.0.0:7005 src/index.js
my_container_1 | Thu, 24 May 2018 15:30:47 GMT nodemon bus new listener: exit (1)
my_container_1 | Thu, 24 May 2018 15:30:47 GMT nodemon start watch on: ./,../shared/
my_container_1 | Thu, 24 May 2018 15:30:47 GMT nodemon:watch early exit on watch, still watching (2)
my_container_1 | Unable to open devtools socket: address already in use
my_container_1 | [nodemon] app crashed - waiting for file changes before starting...
Let me know if I can assist further.
Maybe retry the spawn until the port is available would be a good workaround until we find the issue that is causing the port to be in use for more time then the bus: exit be emitted.
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.
Thank you for contributing <3
I'm also running into this inside of a Docker container (Docker for Windows)
Hi @remy, i'm experiencing this issue too as well as the others
Node: 9.10.1
npm: 6.1.0
Nodemon: 1.17.5
OS: Windows 10
Command you ran: nodemon app
Here is a link to my repo: https://github.com/AlexanderYW/uptime
I'm getting the error on this one
I'm experiencing the same issue
From #1050 I tried the workaround of that comment
nodemon --delay 80ms --exec 'fuser -k 56745/tcp; node --inspect=0.0.0.0:56745 ./app/http.js'
replaced kill-port with fuser
Can we mark this as worked around (I suspect the fact it's nodemon plus node plus debugger protocol plus docker plus host system - might make the inception like debugging silly hard - certainly no one has offered any PRs, so I'm guessing I'm right on that one).
I'm happy to add this to the faq too.
(added to faq)
Here is a repo that replicates this issue: https://github.com/darkobits/nodemon-restart-issue.
It seems that Nodemon isn't waiting for the old process to completely exit before starting a new one, but _only_ when in a Docker container and _only_ when debug mode is active.
To be clear: The presence of --inspect _does_ cause the new process to immediately crash because its trying to open a server on the same port that is still in use by the previous process, but this merely a side-effect of this issue. You will notice that even in the Docker container, if the --inspect flag is removed, Nodemon correctly waits for the old process to exit, but when --inspect is used inside the container, Nodemon _does not_ wait for the process to exit.
I hope this helps.
P.S. -- 馃憦 to Remy and the other contributors to this fantastic project. 馃樃
@darkobits you're better off starting a new issue for what you're seeing (particularly useful as you have a repo to replicate). I prefer to work with fresh issues (particularly when there's been a bunch of time since closing and reporting new findings).
Thans again for the repo to replicate 馃憤
This happens to me outside of docker: https://github.com/nomcopter/nodemon-no-wait-repro
Adding "signal": "SIGINT" to the nodemon.json fixed this for me
@Christilut When im adding the signal SIGINT to the nodemon.json it keeps restarting, the errrors are gone but this is also not a good solution. Do you have any idea why the signal sigint can cause this?
No idea but this is the full config I'm using, maybe it helps:
nodemon.json
{
"restartable": "rs",
"ignore": [
".git",
"node_modules/**/node_modules"
],
"verbose": false,
"execMap": {
"ts": "node --require ts-node/register"
},
"watch": [
"server/",
"config/"
],
"ext": "json,ts",
"signal": "SIGINT"
}
Start with (as NPM script): nodemon --inspect server/index.ts
So the trick with fuser kinda worked for me,
but still at times it would not manage to kill the process before starting a new one.
So I resolved it by using a while loop to make sure we don't move on until the old process is definitely killed.
here is my solution:
nodemon --delay 100ms --exec 'while [ -n "$(fuser -k 9229/tcp)" ]; do sleep 0.1; done; node --inspect=0.0.0.0:9229 ./src/app.js'
Hope this helps someone in the future
Bizarrely changing the signal to SIGINT also solves the problem for me. I do not have Docker in the mix.
After using SIGINT, nodemon restarts but can't kill the process when debugger is attached and process is paused (i.e. user is currently stepping via code):

my package.json configuration:
"start:dev": "nodemon --exec node --inspect=0.0.0.0:5860 ."
},
"nodemonConfig": {
"ignore": [
".git",
"cache/*",
"logs/*"
],
"env": {
"NODE_ENV": "test"
},
"signal": "SIGINT",
"verbose": true
},
Most helpful comment
I'm experiencing the same issue
From #1050 I tried the workaround of that comment
replaced kill-port with fuser