Description
Currently, Node.js process does not start if the specified debug port is already bound by some another process.
These steps allow to reproduce this behavior (node 5.2.0).
// test.js
console.log('Hello, world');
process.stdin.resume();
Running node --debug=54138 test.js
outputs
Debugger listening on port 54138
Hello, world
and does not exit.
Running another node --debug=54138 test.js
outputs
Error: listen EADDRINUSE :::54138
at Object.exports._errnoException (util.js:856:11)
at exports._exceptionWithHostPort (util.js:879:20)
at Agent.Server._listen2 (net.js:1238:14)
at listen (net.js:1274:10)
at Agent.Server.listen (net.js:1370:5)
at Object.start (_debug_agent.js:22:9)
at startup (node.js:72:9)
at node.js:977:3
and hangs.
It might seem like an expected behavior, unless it interferes with the common pattern of spawning child node processes - child node process command lines are usually constructed using process.execArgv
of the main node process. Thus, if the main node process is started in debug mode, child processes will hang unless there is a special handling of process.execArgv
that takes care of --debug/--debug-brk
.
What do you think if node would try to bind a specified debug port increasing it by one until it succeeds?
Tools can always figure out the really bound debug port by stderr analyzing.