-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
Description
- Version: 7.10.0
- Platform: any
- Subsystem: cluster
Given the following code:
const cluster = require('cluster')
if (cluster.isMaster) {
cluster.setupMaster({
execArgv: [
'--debug=1337'
]
})
cluster.fork()
} else {
setInterval(() => true, 1000)
}I get the following output on the console at runtime:
Debugger listening on port 5859
The reason for this is because the current code assumes that whatever flag present in execArgv will be the same as the one being passed to the master process, and therefore extracts the initial port from process.debugPort instead (ref: https://github.com/nodejs/node/blob/master/lib/internal/cluster/master.js#L98-L119). It also assumes that the first port will be used to debug the master, and automatically increment the port for the first worker. Finally, given the submitted code, one would arguably expect no increments to happen at all; in the actual use-case where I wish to make sure of this pattern, I use cluster with one and only one worker at a time, so re-using the same port would be perfectly fine.
I would be more than happy to contribute a fix, but given the current behaviour and the fact that I don't know how I could actually distinguish programatic setup from the initial extraction of execArgv passed to the master process, I am having a bit of a hard time to figure out how to approach this issue. Suggestions more than welcome.