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

error Error: listen EADDRINUSE :::5858 when using node debug #533

Closed
alexklibisz opened this issue May 13, 2016 · 7 comments
Closed

error Error: listen EADDRINUSE :::5858 when using node debug #533

alexklibisz opened this issue May 13, 2016 · 7 comments

Comments

@alexklibisz
Copy link

I'm using node 6.0.0 and commander ^2.9.0. I'm trying to use the built-in node debugger to inspect at some breakpoints.

Case 1: If I run a script that doesn't use commander, it works:

src/cli/works.js:

var x = 5;
setTimeout(() => {
  debugger;
  console.log('world');
}, 1000);
console.log('hello');
$ node debug src/cli/works.js 
< Debugger listening on port 5858
connecting to 127.0.0.1:5858 ... ok
break in src/cli/works.js:1
> 1 var x = 5;
  2 setTimeout(() => {
  3   debugger;
debug> cont
< hello
break in src/cli/works.js:3
  1 var x = 5;
  2 setTimeout(() => {
> 3   debugger;
  4   console.log('world');
  5 }, 1000);
debug> cont
< world
debug> 

Case 2: If I run my commander script without debug, it also works:

src/cli/cli.js

const
  cli = require('commander'),
  pkg = require('../../package.json');

cli
  .version(pkg.version)
  .command('grid', 'creates grid-style visualization')
  .parse(process.argv);

src/cli/cli-grid.js

debugger;
console.log('grid');
$ node src/cli/cli.js grid
grid

Case 3: But if I run a script with the commander and the debug option, it gives the following error:

$ node debug src/cli/cli.js grid
< Debugger listening on port 5858
connecting to 127.0.0.1:5858 ... ok
break in src/cli/cli.js:1
> 1 const
  2   cli = require('commander'),
  3   pkg = require('../../package.json');
debug> cont
< Error: listen EADDRINUSE :::5858
<     at Object.exports._errnoException (util.js:896:11)
<     at exports._exceptionWithHostPort (util.js:919:20)
<     at Agent.Server._listen2 (net.js:1246:14)
<     at listen (net.js:1282:10)
<     at Agent.Server.listen (net.js:1378:5)
<     at Object.start (_debug_agent.js:21:9)
<     at startup (node.js:85:44)
<     at node.js:444:3
debug> cont
debug> cont
debug> cont

So it seems that there's some sort of issue being cause by using the debugger and commander at the same time. I've searched other issues, but found nothing directly relevant. Thanks in advance.

@rebeccapeltz
Copy link

I am experiencing the same problem after an upgrade today.

@remolueoend
Copy link

Just ran in the same problem. When using git-style sub-commands, commander.js spawns a new node-process to execute the sub-command which is located in a separate js-file. When spawning a new process, commander.js is copying all original process arguments to the new process, including --debug, --debug-brk etc. (

args = (process.execArgv || []).concat(args);
). That means a new node-process is started trying to listen on port 5858 too and fails because the original node-process is blocking the port.

To fix this, try to debug the sub-command directly:

node --debug my-tool-subcommand.js

Instead of calling the main script using the sub-command as argument:

node --debug my-tool.js subcommand // fails!

@radekk
Copy link

radekk commented Oct 28, 2016

It should be added to the documentation, thanks @remolueoend, it works.

@alexklibisz
Copy link
Author

If it's considered fixed please feel free to close it. I had forgotten I opened it! :)

@shadowspawn
Copy link
Collaborator

This looks like might be a solution on node side?

nodejs/node#5025

bind to random port with --debug-port=0

@shadowspawn
Copy link
Collaborator

This issue will be resolved when v3.0.0 is released. Available now as a prerelease. See #1001

@shadowspawn
Copy link
Collaborator

If you are using the node inspector for debugging git-style executable (sub)commands using node -inspect et al, the inspector port is incremented by 1 for the spawned subcommand.

Shipped in v3: https://github.com/tj/commander.js/releases/tag/v3.0.0

Thanks to suggestion by @tcf909

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

5 participants