Skip to content
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 crashes first restart then works ok the second one when started like nodemon --inspect=0.0.0.0:9229 app.js #1050

Closed
rluncasu opened this issue Jun 15, 2017 · 18 comments

Comments

@rluncasu
Copy link

nodemon --inspect=0.0.0.0:9229 /app/server.js

inside a container based on

FROM node:8.1.0

with a shared volume on sources. Whenever I save a file on the sources volume, nodemon restarts but crashes with

[nodemon] restarting due to changes...
  nodemon bus emit: restart +13s
  nodemon bus.emit(exit) via SIGUSR2 +14ms
  nodemon bus emit: exit +0ms
[nodemon] starting `node --inspect=0.0.0.0:9229 /app/server.js`
  nodemon spawning node --inspect=0.0.0.0:9229 /app/server.js +1ms
  nodemon bus emit: start +7ms
  nodemon bus new listener: exit (1) +1ms
  nodemon start watch on: *.* +0ms
  nodemon:watch early exit on watch, still watching (1) +1ms
Starting inspector on 0.0.0.0:9229 failed: address already in use
[nodemon] app crashed - waiting for file changes before starting...

Re-saving the same file, again restarts but works ok this time.

@Thr1ve
Copy link

Thr1ve commented Jul 20, 2017

I ran into this issue as well when using nodemon with the inspect flag within a docker container. Oddly, it only seems to happen when I add heapdump to the project along with the requisite python dependency for node-gyp. If I remove heapdump, it works as expected.

Perhaps this is related to using a native module somehow?

@leaanthony
Copy link

This has been an issue for me also. Ideally there'd be a flag specifying a delay between shutdown and startup so that the tcp port has enough time to close.

@yujiahaol68
Copy link

Just kill inspector and start inspector again
here is our team's solution in our package.json

"inspect": "kill-port --port 9229 && node --inspect=0.0.0.0:9229 build/startup.js",
"start_watch_inspect": "nodemon --delay 80ms --watch build/ build/startup.js --exec 'npm run inspect'",

@rluncasu
Copy link
Author

rluncasu commented Nov 9, 2017

@yujiahaol68 good workaround, just used it, thanks !

@Dim73
Copy link

Dim73 commented Nov 23, 2017

@yujiahaol68 What is the kill-port command? I don't have this one

@yujiahaol68
Copy link

yujiahaol68 commented Nov 24, 2017

That is a npm package. A command line tool. @Dim73

@remy
Copy link
Owner

remy commented Nov 24, 2017

Closing with the work around mentioned earlier.

@TristanMarion
Copy link

As mentionned here, instead of the kill-port package you can use fuser which is an UNIX command.

@DimitrK
Copy link

DimitrK commented Jan 5, 2019

If there is no reason to update nodemon, previous version 1.17.4 seems to work trouble free.

@justinpage
Copy link

justinpage commented Jan 15, 2019

@DimitrK Keep in mind that 1.18.7 and above resolves a major vulnerability with pstree:

21e052e

@mukuljainx
Copy link

Hey everyone, updating nodemon from version 1.18.6 to 1.18.9 fixed the issue for me.

@johnbindel
Copy link

Works with fuser command even in alpine images without requiring the kill-port package:

nodemon --delay 80ms --exec 'fuser -k 56745/tcp; node --inspect=0.0.0.0:56745 ./app/http.js'

Credit to @abou7mied: #1346 (comment)

@jwhitmarsh
Copy link

MacOS equivalent for fuser which doesn't ship with the k flag:

nodemon --exec lsof -nti:56745 | xargs kill -9; node --inspect=0.0.0.0:56745 index.js

@Cleomir
Copy link

Cleomir commented Aug 3, 2019

Works with fuser command even in alpine images without requiring the kill-port package:

nodemon --delay 80ms --exec 'fuser -k 56745/tcp; node --inspect=0.0.0.0:56745 ./app/http.js'

Credit to @abou7mied: #1346 (comment)

Adding --delay 80ms solved my problem.

@kasvtv
Copy link

kasvtv commented Oct 10, 2019

I don't understand how this got closed. This is a pretty common setup and the workaround is hacky.

@andness
Copy link

andness commented Nov 8, 2019

I just ran into this and I very much agree with @kasvtv, it seems very strange to just close the issue. Running dev environments in docker containers seems pretty common these days?

@santiagosemhan
Copy link

Nowaday it's super common to have nodemon running on docker containers, so I think this ticket should be reopened. I don't know how nodemon works internally but I think having an internal flag that indicates to process to close the port and then watch files again could be a simple workaround.

@remy
Copy link
Owner

remy commented Apr 14, 2020

Short reply - I don't use docker (not once for any client project or side project), so please send PR to fix with tests that show the fix works. Happy to merge. Otherwise, this issue is closed because there's a solution (pending your PRs). Sorry (docker) folks, just saying 'I think this is strange' doesn't solve the core issue. Ta.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests