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

Starting inspector on 0.0.0.0:9229 failed: address already in use #1492

Closed
xDelph opened this issue Dec 14, 2018 · 19 comments
Closed

Starting inspector on 0.0.0.0:9229 failed: address already in use #1492

xDelph opened this issue Dec 14, 2018 · 19 comments
Labels

Comments

@xDelph
Copy link

xDelph commented Dec 14, 2018

  • nodemon -v: 1.18.8
  • node -v: 9.4.0
  • Operating system/terminal environment: ubuntu 18.04
  • Using Docker? What image: docker -> FROM node:slim
  • Command you ran: ./node_modules/.bin/nodemon --inspect=0.0.0.0 --legacy-watch ./src ./src/index.js

Expected behaviour

inspector restart on file change

Actual behaviour

Starting inspector on 0.0.0.0:9229 failed: address already in use

Steps to reproduce

using a dockerfile like :

FROM node:slim

# Create app directory
WORKDIR /usr/app

# Install app dependencies
COPY package.json /usr/app/
RUN npm install

# Bundle app source
COPY . /usr/app

CMD [ "npm", "run", "watch" ]
@remy
Copy link
Owner

remy commented Dec 14, 2018

Is the watch scripts entry the same as ./node_modules/.bin/nodemon --inspect=0.0.0.0 --legacy-watch ./src ./src/index.js?

And can you replicate with this script:

require('http').createServer((req, res) => res.end('ok')).listen(8000);

@remy remy added needs more info not enough information in issue to debug docker labels Dec 14, 2018
@xDelph
Copy link
Author

xDelph commented Dec 14, 2018

Is the watch scripts entry the same as ./node_modules/.bin/nodemon --inspect=0.0.0.0 --legacy-watch ./src ./src/index.js?

And can you replicate with this script:

require('http').createServer((req, res) => res.end('ok')).listen(8000);

yes, this is the watch entry
and yes i replicate the problem with index.js containing only this line of code

@xDelph
Copy link
Author

xDelph commented Dec 14, 2018

here is my package.json if needed

{
  "name": "",
  "version": "1.4.1",
  "main": "index.js",
  "scripts": {
    "start": "node ./src/index.js",
    "watch": "./node_modules/.bin/nodemon --inspect --watch ./src ./src/index.js",
    "test": "echo 'no test implemented !!'"
  },
  "license": "MIT",
  "dependencies": {
    "axios": "^0.18.0",
    "body-parser": "^1.18.3",
    "dotenv": "^6.0.0",
    "express": "^4.16.3",
    "foreman": "^3.0.1",
    "jsonwebtoken": "^8.3.0",
    "mongodb": "^2.2.14",
    "mssql": "^4.1.0",
    "nodemon": "^1.18.8"
  }
}

docker-compose : 1.22.0
docker : 18.09.0

@remy
Copy link
Owner

remy commented Dec 14, 2018

Can you provide a full working Dockerfile and docker-compose.yml file? I know very little about docker, so it's hard for me to replicate fully to debug. (and possibly how to start the container…)

@xDelph
Copy link
Author

xDelph commented Dec 14, 2018

you will find a project setup to reproduce the issue here : https://github.com/xDelph/nodemon-issue-inspector

just launch docker-compose up at the root

@remy
Copy link
Owner

remy commented Dec 14, 2018

Sorry - I've just solved the issue (with a lot of messing on the command line).

If you do a hard upgrade of nodemon, it should include the latest pstree.remy@1.1.5 (a quick check with npm ls pstree.remy should validate). If you have that sub-dep, then you'll find it properly kills the inspector.

@remy remy removed the needs more info not enough information in issue to debug label Dec 14, 2018
@xDelph
Copy link
Author

xDelph commented Dec 14, 2018

Step 6/9 : RUN npm ls pstree.remy
 ---> Running in 97c4d86b2c37
 /usr/app
`-- nodemon@1.18.8
  `-- pstree.remy@1.1.5 

the version of pstree.remy seems ok now in my docker
but now i get :

/usr/app/node_modules/pstree.remy/lib/index.js:25
webapi_1  |     .catch(error => callback(error));
webapi_1  |                                    ^
webapi_1  | 
webapi_1  | SyntaxError: missing ) after argument list
webapi_1  |     at new Script (vm.js:83:7)
webapi_1  |     at createScript (vm.js:267:10)
webapi_1  |     at Object.runInThisContext (vm.js:319:10)
webapi_1  |     at Module._compile (internal/modules/cjs/loader.js:686:28)
webapi_1  |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:734:10)
webapi_1  |     at Module.load (internal/modules/cjs/loader.js:620:32)
webapi_1  |     at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
webapi_1  |     at Function.Module._load (internal/modules/cjs/loader.js:552:3)
webapi_1  |     at Module.require (internal/modules/cjs/loader.js:659:17)
webapi_1  |     at require (internal/modules/cjs/helpers.js:22:18)


which is very weird

@remy
Copy link
Owner

remy commented Dec 14, 2018

Yeah, my bad for being a plum. Re-install and .6 is good 😢

@xDelph
Copy link
Author

xDelph commented Dec 14, 2018

great, it's ok now
thanks for your help ;)

@remy remy closed this as completed Dec 14, 2018
@justinpage
Copy link

As described in #1476 I'm still seeing this issue with 1.18.9.

The issue is intermittent with the following start command:

./node_modules/.bin/nodemon --inspect=0.0.0.0:9229 ./index.js

@JonDum
Copy link

JonDum commented Apr 10, 2019

I get this issue all the time. Not sure when exactly it started happening, but it didn't use to happen.

node v11.11.0 via alpine-v11

─┬ nodemon@1.18.10
  └── pstree.remy@1.1.6
"dev": "nodemon -L -d 2 --inspect=0.0.0.0:9229 -- --icu-data-dir=$NODE_ICU_DATA_PATH index.js"

Would be happy to retrieve any logs or additional info to help narrow this down.

@srfrnk
Copy link

srfrnk commented Apr 12, 2019

I get this issue all the time. Not sure when exactly it started happening, but it didn't use to happen.

node v11.11.0 via alpine-v11

─┬ nodemon@1.18.10
  └── pstree.remy@1.1.6
"dev": "nodemon -L -d 2 --inspect=0.0.0.0:9229 -- --icu-data-dir=$NODE_ICU_DATA_PATH index.js"

Would be happy to retrieve any logs or additional info to help narrow this down.

@JonDum - Happens to me as well. See logs below:

[nodemon] starting `node --inspect -r ts-node/register ./src/index.ts`
Debugger listening on ws://127.0.0.1:9229/5c2962b0-43a0-4210-93ac-fc81e6d537f8
For help, see: https://nodejs.org/en/docs/inspector
Example app listening on port 3000!
[nodemon] restarting due to changes...
[nodemon] starting `node --inspect -r ts-node/register ./src/index.ts`
Debugger listening on ws://127.0.0.1:9229/f0c7fdda-8b0f-4ebe-8a79-37099d8596d6
For help, see: https://nodejs.org/en/docs/inspector
Example app listening on port 3000!
[nodemon] restarting due to changes...
[nodemon] starting `node --inspect -r ts-node/register ./src/index.ts`
Debugger listening on ws://127.0.0.1:9229/3336a7df-a763-440e-9e92-20ec0811726b
For help, see: https://nodejs.org/en/docs/inspector
Example app listening on port 3000!
[nodemon] restarting due to changes...
[nodemon] starting `node --inspect -r ts-node/register ./src/index.ts`
[nodemon] restarting due to changes...
Debugger listening on ws://127.0.0.1:9229/cc164e40-316f-4b07-8bc2-c2dc80f5d515
For help, see: https://nodejs.org/en/docs/inspector
[nodemon] starting `node --inspect -r ts-node/register ./src/index.ts`
Debugger listening on ws://127.0.0.1:9229/86884f82-93b2-4885-a580-3f29b00f1065
For help, see: https://nodejs.org/en/docs/inspector
Example app listening on port 3000!
[nodemon] restarting due to changes...
[nodemon] starting `node --inspect -r ts-node/register ./src/index.ts`
[nodemon] app crashed - waiting for file changes before starting...
Starting inspector on 127.0.0.1:9229 failed: address already in use
[nodemon] restarting due to changes...
[nodemon] starting `node --inspect -r ts-node/register ./src/index.ts`
[nodemon] app crashed - waiting for file changes before starting...
Starting inspector on 127.0.0.1:9229 failed: address already in use
[nodemon] restarting due to changes...
[nodemon] starting `node --inspect -r ts-node/register ./src/index.ts`
[nodemon] app crashed - waiting for file changes before starting...
Starting inspector on 127.0.0.1:9229 failed: address already in use
[nodemon] restarting due to changes...
[nodemon] starting `node --inspect -r ts-node/register ./src/index.ts`
[nodemon] app crashed - waiting for file changes before starting...
Starting inspector on 127.0.0.1:9229 failed: address already in use

@csalvato
Copy link

csalvato commented Apr 27, 2019

Happens to me as well:

nodemon@^1.18.11:
  version "1.18.11"
  resolved "https://registry.yarnpkg.com/nodemon/-/nodemon-1.18.11.tgz#d836ab663776e7995570b963da5bfc807e53f6b8"
  integrity sha512-KdN3tm1zkarlqNo4+W9raU3ihM4H15MVMSE/f9rYDZmFgDHAfAJsomYrHhApAkuUemYjFyEeXlpCOQ2v5gtBEw==
  dependencies:
    chokidar "^2.1.5"
    debug "^3.1.0"
    ignore-by-default "^1.0.1"
    minimatch "^3.0.4"
    pstree.remy "^1.1.6"
    semver "^5.5.0"
    supports-color "^5.2.0"
    touch "^3.1.0"
    undefsafe "^2.0.2"
    update-notifier "^2.5.0"

Not sure why it's happening. Here's my package.json script...:

"dev": "nodemon app.js --exec babel-node --inspect --"

@srfrnk
Copy link

srfrnk commented Apr 27, 2019

Maybe my workaround can help you guys:
https://stackoverflow.com/questions/43898947/docker-node-app-always-crashes-on-file-change-using-nodemon/55881699#55881699

@Shahor
Copy link

Shahor commented Aug 27, 2019

Sorry for upping this, but I'm having the exact same issue :|

[edit]: Seems to be working fine with --signal SIGINT but it prevents the process from getting killed in development.

It's fine in my case because it's running in docker, but that's probably not something fine

@ssas01
Copy link

ssas01 commented Oct 28, 2019

My code is wrong, so it appears.

@nanxiaobei
Copy link

nanxiaobei commented Jun 11, 2020

Just add --delay 300ms into the command solved my problem.

https://github.com/remy/nodemon#delaying-restarting

@Arman92
Copy link

Arman92 commented Jan 8, 2021

Just add --delay 300ms into the command solved my problem.

https://github.com/remy/nodemon#delaying-restarting

Thank you, it fixed in my case.

@erikeckhardt
Copy link

I fixed my problem by changing the npm dev script and the nodemon exec command, to move the time of setting NODE_OPTIONS later, from this:

package.json: "dev": "NODE_OPTIONS=--inspect=0.0.0.0:9229 nodemon -L src/index.ts"
nodemon.json: "exec": "ts-node -r dotenv/config"

to this:

package.json: "dev": "nodemon -L src/index.ts"
nodemon.json: "exec": "NODE_OPTIONS=--inspect=0.0.0.0:9229 ts-node -r dotenv/config"

What must have been happening was that node and/or nodemon was taking over listening on the port, but ts-node was also trying to do the same thing. By setting the environment variable later, that is avoided.

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

No branches or pull requests