node icon indicating copy to clipboard operation
node copied to clipboard

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

Open melnikaite opened this issue 11 years ago • 23 comments

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

$ npm start

> [email protected] 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.

  • node v4.2.1
  • node-inspector v0.12.3
  • nodemon v1.7.1
  • express v4.13.3

melnikaite avatar Oct 21 '15 10:10 melnikaite

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.

bnoordhuis avatar Oct 21 '15 12:10 bnoordhuis

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

melnikaite avatar Oct 21 '15 14:10 melnikaite

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

evanlucas avatar Oct 21 '15 14:10 evanlucas

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

melnikaite avatar Oct 21 '15 14:10 melnikaite

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

evanlucas avatar Oct 21 '15 15:10 evanlucas

$ 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.

melnikaite avatar Oct 21 '15 15:10 melnikaite

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?

evanlucas avatar Oct 21 '15 15:10 evanlucas

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.

melnikaite avatar Oct 21 '15 16:10 melnikaite

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.

evanlucas avatar Oct 21 '15 18:10 evanlucas

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

kaplandani avatar Nov 23 '15 15:11 kaplandani

@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.

cjihrig avatar Nov 23 '15 15:11 cjihrig

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 🔫🎓

Wuntenn avatar Sep 07 '16 14:09 Wuntenn

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.

durrellchamorro avatar Sep 10 '16 04:09 durrellchamorro

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.

dnbr2002 avatar Jan 06 '17 15:01 dnbr2002

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

ghost avatar Mar 16 '17 14:03 ghost

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.

praWINK avatar Apr 12 '17 12:04 praWINK

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 . . .

GamerBoy1 avatar Jun 29 '17 15:06 GamerBoy1

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.

mikerames avatar May 05 '18 09:05 mikerames

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

HansaTheDeveloper avatar Jul 02 '18 12:07 HansaTheDeveloper

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.

elpapichivo avatar Jul 19 '18 13:07 elpapichivo