nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
107.58k stars 29.59k forks source link

Can't run app with debugger: Error: listen EADDRINUSE :::5858 #3469

Closed melnikaite closed 9 years ago

melnikaite commented 9 years ago

I have application built on express framework. My start script in package.json is nodemon --debug ./bin/www.

$ npm start

> MyApp@0.5.0 start /Users/me/projects/myapp
> nodemon --debug ./bin/www

21 Oct 13:19:47 - [nodemon] 1.7.3
21 Oct 13:19:47 - [nodemon] to restart at any time, enter `rs`
21 Oct 13:19:47 - [nodemon] watching: *.*
21 Oct 13:19:47 - [nodemon] starting `node --debug ./bin/www`
Debugger listening on port 5858
Logger level: 4
Error: listen EADDRINUSE :::5858
    at Object.exports._errnoException (util.js:874:11)
    at exports._exceptionWithHostPort (util.js:897:20)
    at Agent.Server._listen2 (net.js:1234:14)
    at listen (net.js:1270:10)
    at Agent.Server.listen (net.js:1366:5)
    at Object.start (_debug_agent.js:21:9)
    at startup (node.js:70:9)
    at node.js:961:3

I've checked that nobody is listening 5858 before npm start and after stopping script. Everything is fine without debug flag. It seems debug server starts twice, because I see that one node process is listening 5858 port. Protractor users experience similar issue https://github.com/angular/protractor/issues/2039.

bnoordhuis commented 9 years ago

I don't think this is a bug in node. You're using nodemon and it probably isn't smart enough to replace the --debug switch with one that includes a unique port number.

melnikaite commented 9 years ago

I just tried to run without nodemon, but still have the same error

$ node --debug bin/www 
Debugger listening on port 5858
Logger level: 4
Error: listen EADDRINUSE :::5858
    at Object.exports._errnoException (util.js:874:11)
    at exports._exceptionWithHostPort (util.js:897:20)
    at Agent.Server._listen2 (net.js:1234:14)
    at listen (net.js:1270:10)
    at Agent.Server.listen (net.js:1366:5)
    at Object.start (_debug_agent.js:21:9)
    at startup (node.js:70:9)
    at node.js:961:3
evanlucas commented 9 years ago

Can you try running with the NODE_DEBUG="http,net" environment variable?

melnikaite commented 9 years ago

Sure

$ NODE_DEBUG="http,net" node --debug bin/www 
NET 43499: listen2 null 5858 4 false undefined
NET 43499: _listen2: create a handle
NET 43499: bind to ::
Debugger listening on port 5858
Logger level: 4
NET 43499: listen2 null 8080 4 false undefined
NET 43499: _listen2: create a handle
NET 43499: bind to ::
NET 43499: listen2 0.0.0.0 3003 4 false undefined
NET 43499: _listen2: create a handle
NET 43499: bind to 0.0.0.0
NET 43500: listen2 null 5858 4 false undefined
NET 43500: _listen2: create a handle
NET 43500: bind to ::
Error: listen EADDRINUSE :::5858
    at Object.exports._errnoException (util.js:874:11)
    at exports._exceptionWithHostPort (util.js:897:20)
    at Agent.Server._listen2 (net.js:1234:14)
    at listen (net.js:1270:10)
    at Agent.Server.listen (net.js:1366:5)
    at Object.start (_debug_agent.js:21:9)
    at startup (node.js:70:9)
    at node.js:961:3
evanlucas commented 9 years ago

ok and can you paste the output of running NODE_DEBUG="net" node bin/www please?

melnikaite commented 9 years ago
$ NODE_DEBUG="net" node bin/www
Logger level: 4
NET 44785: listen2 null 8080 4 false undefined
NET 44785: _listen2: create a handle
NET 44785: bind to ::
NET 44785: listen2 0.0.0.0 3003 4 false undefined
NET 44785: _listen2: create a handle
NET 44785: bind to 0.0.0.0
NET 44786: createConnection [ { port: 27017, host: 'localhost' } ]
NET 44786: pipe false undefined
NET 44786: connect: find host localhost
NET 44786: connect: dns options { family: undefined, hints: 3072 }
NET 44786: _read
NET 44786: _read wait for connection
NET 44786: afterConnect
NET 44786: _read
NET 44786: Socket._read readStart
NET 44786: onread 194
NET 44786: got data
NET 44786: destroy undefined
NET 44786: destroy
NET 44786: close
NET 44786: close handle
NET 44786: _read
NET 44786: _read wait for connection
NET 44786: emit close
NET 44786: createConnection [ { port: 27017, host: 'localhost' } ]
NET 44786: pipe false undefined
NET 44786: connect: find host localhost
NET 44786: connect: dns options { family: undefined, hints: 3072 }
NET 44786: createConnection [ { port: 27017, host: 'localhost' } ]
NET 44786: pipe false undefined
NET 44786: connect: find host localhost
NET 44786: connect: dns options { family: undefined, hints: 3072 }
NET 44786: _read
NET 44786: _read wait for connection
NET 44786: _read
NET 44786: _read wait for connection
NET 44786: createConnection [ { port: 27017, host: 'localhost' } ]
NET 44786: pipe false undefined
NET 44786: connect: find host localhost
NET 44786: connect: dns options { family: undefined, hints: 3072 }
NET 44786: createConnection [ { port: 27017, host: 'localhost' } ]
NET 44786: pipe false undefined
NET 44786: connect: find host localhost
NET 44786: connect: dns options { family: undefined, hints: 3072 }
NET 44786: createConnection [ { port: 27017, host: 'localhost' } ]
NET 44786: pipe false undefined
NET 44786: connect: find host localhost
NET 44786: connect: dns options { family: undefined, hints: 3072 }
NET 44786: _read
NET 44786: _read wait for connection
NET 44786: _read
NET 44786: _read wait for connection
NET 44786: _read
NET 44786: _read wait for connection
NET 44786: afterConnect
NET 44786: _read
NET 44786: Socket._read readStart
NET 44786: afterConnect
NET 44786: _read
NET 44786: Socket._read readStart
NET 44786: afterConnect
NET 44786: _read
NET 44786: Socket._read readStart
NET 44786: afterConnect
NET 44786: _read
NET 44786: Socket._read readStart
NET 44786: afterConnect
NET 44786: _read
NET 44786: Socket._read readStart
NET 44786: onread 194
NET 44786: got data
NET 44786: _read
Connected to MongoDB.
evanlucas commented 9 years ago

Ok, there isn't much for us to go on at this point without seeing some code. Do you have a test case you could share possibly?

melnikaite commented 9 years ago

I replaced var dbProcess = childProcess.fork('./database-service/database-process.js'); with var dbProcess = childProcess.fork('./database-service/database-process.js', [], {execArgv: ['--debug=5859']}); to fix my problem.

evanlucas commented 9 years ago

Ah that makes more sense. child_process.fork will use process.execArgv if the options object passed to it does not have execArgv. So both processes were using the debugger on the same port.

kaplandani commented 8 years ago

I have the same issue trying to debug with webstrom. Didn't understand the workaround - how can I make it work ?

cjihrig commented 8 years ago

@kaplandani if your application is creating a child process, it will try to use the same debugger port. You can prevent that by explicitly setting a debug port, as explained in https://github.com/nodejs/node/issues/3469#issuecomment-149961323.

Wuntenn commented 8 years ago

I just had the same issue. It's most likely that node didn't shut down properly.

Just run: ps aux | grep node

Get the process ID of the culprit and run: kill <PID>

If that doesn't work it node (most likely due to open sockets) use stronger: kill SIGKILL <PID>

More info on becoming a process assassin here 🔫🎓

durrellchamorro commented 8 years ago

I had the same issue. I ran:

$ ps aux | grep node

to get the process id, then:

$ sudo kill -9 

followed by the process id to kill the process.

dnbr2002 commented 7 years ago

I had 2 Visual Studio Code windows open. This thread made me realize I prob had port conflicts so I shutdown all Visual Studio Code projects I had open and restarted just the project I wanted to debug. No more problem. Debugger worked fine. So just resolve the port conflict is the simplest solution IMO.

ghost commented 7 years ago

For me, this error happened when my VM was terminated remotely. In my case, running vagrant reload solved the issue.

praWINK commented 7 years ago

You can solve it by two ways.

  1. first and preferred one is @durrellchamorro answer. you ran the command ps aux | grep node and you will get the process id like 16750 or some other else, next you need to run kill -9 16750 it will kill the process. 2.Next one is run the command killall -9 node it will kill all the processing running on node.
GamerBoy1 commented 7 years ago

Hey i need help with this problem

events.js:160 throw er; // Unhandled 'error' event ^

Error: listen EADDRINUSE :::8081 at Object.exports._errnoException (util.js:1018:11) at exports._exceptionWithHostPort (util.js:1041:20) at Server._listen2 (net.js:1258:14) at listen (net.js:1294:10) at Server.listen (net.js:1390:5) at Object. (C:\Users\Briscan\Desktop\LazarBots\c.js:18:5) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12)

C:\Users\Desktop\LazarBots>pause Press any key to continue . . .

mikerames commented 6 years ago

i was having that error because i was already running nodemon on the back. stopping it and re-running debug mode in visual studio code, worked fine.

HansaTheDeveloper commented 6 years ago

Just close the terminal. Start again and run npm start and erorr will not list again. Thank you.

elpapichivo commented 6 years ago

elpapichivo@DESKTOP-DHPVVNH MINGW64 /c/red_social/api $ sudo kill -9 bash: sudo: command not found

elpapichivo@DESKTOP-DHPVVNH MINGW64 /c/red_social/api $ killall -9 node bash: killall: command not found

elpapichivo@DESKTOP-DHPVVNH MINGW64 /c/red_social/api $ ps aux | grep node

elpapichivo@DESKTOP-DHPVVNH MINGW64 /c/red_social/api $ killall -9 bash: killall: command not found

elpapichivo@DESK

It doesn't work for me. I cant understund why.

loganripplinger commented 6 years ago

https://github.com/nodejs/node/issues/3469#issuecomment-406283346 It looks like you're using gitbash on windows. killall works on linux systems, not windows. Use windows friendly commands.

barriosnahuel commented 5 years ago

I faced the same issue recently but in my case the problem was because of the commander package. I used this https://github.com/tj/commander.js/issues/533#issuecomment-244063659 workaround to fix it.

parthibansettu commented 5 years ago

Hi I am using Javascript with cucumber and i am trying to add debug feature in the framework using VScode and i am facing "C:\Program Files\nodejs\npm.cmd run-script debug Debugger listening on ws://127.0.0.1:1337/3a70b3dd-3378-4eae-8517-405e3ae9f3ba" When i click on "debug" browser is not triggered

Here is my launch.json file

{ // Use IntelliSense to learn about possible Node.js debug attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "Debug", "runtimeExecutable": "npm.cmd", "cwd": "${workspaceRoot}/nodal/", "env":{ "NODE_PATH": "${workspaceRoot}/nodal/node_modules" }, "runtimeArgs": [ "run-script", "debug" ], "port": 1337 } ] }

Here is my package.json file { "name": "nodal", "version": "1.1.5", "description": "End to end UI test automation framework using node,es6,wdio and cucumber", "main": "index.js", "scripts": { "test": "node node_modules/webdriverio/bin/wdio ./config/run_conf.js", "suitetest": "node node_modules/webdriverio/bin/wdio ./config/run_conf.js --suite login", "inspect-test": "node node_modules/webdriverio/bin/wdio ./config/run_conf.js --inspect", "allure-report": "node_modules/.bin/allure generate ./reports/allure-results -c && allure open", "test1": "npm run test && npm run allure-report", "junit-report": "node_modules/.bin/junit-viewer --results=./reports/junit-results --save=junit-results.html && open junit-results.html", "build": "babel feature_generator/server.js", "start-feature": "nodemon feature_generator/server.js --exec babel-node", "start-runner": "nodemon test_runner_and_report_generator/server.js --exec babel-node", "debug": "node --inspect=1337 --debug-brk --nolazy node_modules/cucumber/bin/cucumber-js --tags @debug --format json:./reports/report.json" }, "author": "TAA", "license": "AthenaHealth", "dependencies": { "4": "0.0.0", "@athena/app-fabric-logger": "^3.0.0", "@athena/iam-service-token-manager": "^1.1.1", "@sinonjs/formatio": "^3.2.1", "allure-commandline": "^2.5.0", "assert": "^1.5.0", "axios": "^0.18.0", "babel-cli": "^6.26.0", "babel-polyfill": "^6.26.0", "babel-preset-env": "^1.6.0", "babel-preset-es2015": "^6.24.1", "babel-register": "^6.26.0", "body-parser": "^1.19.0", "cookie-parser": "^1.4.3", "cucumber": "^5.0.2", "date-time": "^2.1.0", "express": "^4.16.4", "graceful-fs": "^4.1.11", "hoek": "^6.1.3", "js-yaml": "^3.13.1", "json-to-pretty-yaml": "^1.2.2", "json2yaml": "^1.1.0", "multer": "^1.4.1", "node-yaml": "^3.2.0", "opn": "^5.5.0", "qs": "^6.7.0", "random-string-generator": "^0.2.0", "regex": "^0.1.1", "replace-ext": "1.0", "rgb-hex": "^2.1.0", "rgba-convert": "^0.3.0", "selenium-grid": "^0.5.0", "tar": "^4.4.6", "wdio-allure-reporter": "^0.6.0", "wdio-dot-reporter": "0.0.5", "wdio-json-reporter": "^0.1.1", "wdio-junit-reporter": "0.0.2", "wdio-spec-reporter": "^0.1.2", "yawn-yaml": "^1.4.0" }, "devDependencies": { "chromedriver": "^2.42.0", "eslint": "^5.16.0", "eslint-config-standard": "^10.2.1", "eslint-plugin-import": "^2.17.2", "eslint-plugin-node": "^5.1.1", "eslint-plugin-promise": "^3.5.0", "eslint-plugin-react": "^3.16.1", "eslint-plugin-standard": "^3.0.1", "inspect-brk": "^0.1.2", "node-cmd": "^3.0.0", "node-dir": "^0.1.17", "node-uuid": "^1.4.7", "nodemon": "^1.19.0", "open": "^6.3.0", "selenium-standalone": "^6.16.0", "wdio-chromedriver-service": "~0.1", "wdio-cucumber-framework": "^1.1.1", "wdio-screenshot": "^0.5.0", "wdio-selenium-standalone-service": "^0.0.10", "webdriverio": "4.13.2" }, "babel": { "presets": [ [ "env", { "targets": { "node": "current" } } ] ], "plugins": [ "transform-object-rest-spread" ] }, "nodemonConfig": { "ignore": [ "./config", "./reports", "./allure-report", "./page_objects", "./step_definitions" ] } }

can you tell me how to fix this issue ?

Wuntenn commented 5 years ago

@parthibansettu Looking at your launch.json you have a debug config called debug available which when clicked results in:

Debugger listening on ws://127.0.0.1:1337/3a70b3dd-3378-4eae-8517-405e3ae9f3ba"

This is good, however you may want to change it to something more descriptive like start as it only opens the program in debug mode and is only the first part: The launcher.

The launcher gets your code running; Now you need to create an attacher. The attacher will need to connect to the debugger session on port 1337 in your case.

To do that click the button that shows whilst the launch.json file is open that says 'add configuration'. Select node attacher from the list. It should generate something like:

        {
            "type": "node",
            "request": "attach",
            "name": "Attach",
            "port": 9229    <---- change yours to 1337 here and you should be all set!!
        } 

After adding this you should be able to select that drop-down attach item and connect to the debugger session that you've been opening with your launcher!