Repository navigation
Programatically setting the debug flag has no effects #12941
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.
Activity
ronkorving commentedon May 10, 2017
disclaimer: I'm a coworker of @stelcheck
It seems very reasonable to me to want to be able to set these on child processes instead of the master process, in situations like process managers etc. I would welcome a fix to this where if the flag was not set on the master process, the port value provided is used, and both
process.debugPortanddebugPortOffsetare ignored.refack commentedon May 12, 2017
[Just my suggestion]
Add a second argument,
opt, tocluster.fork()that will trickle down tocreateWorkerProcessand allow you to override all of the preset opts:(maybe not
envbecause that will cause redundancy)refack commentedon May 12, 2017
[other option]
Get
--inspect-portto be whitelisted in NODE_OPTIONS (#12028)sam-github commentedon May 12, 2017
--inspect-portshould have been inNODE_OPTIONS: #13002sam-github commentedon May 12, 2017
I think what @stelcheck is trying to do is perfectly reasonable, and agree that with the special casing its a bit hard to get all the corner cases.
arturgvieira-zz commentedon May 14, 2017
@refack Hi, I'd like to take this one. I've read over your suggestion, the related code, and made a gist. You mean something like this?
https://gist.github.com/arturgvieira/493772fb633acfb1c8dcaba2d94cfa12
Trott commentedon May 14, 2017
@arturgvieira I could be wrong, but I suspect #13002 is the solution more likely to gain favor than adding a new argument to
cluster.fork(). It hasn't landed yet, though, so I'm somewhat speculating.(Because there's a likely solution proposed and undergoing active review, I'm going to remove the
help wantedlabel from this issue.)arturgvieira-zz commentedon May 14, 2017
@Trott Thanks, I must have missed the reference to the open PR.
25 remaining items
refack commentedon Jun 13, 2017
AFAIK @mutantcornholio second phase is to give the user a manual opt-out of auto-incrementing or a way disconnect the workerID from the debugger port.
ref-counting workerIDs will be good anyway.
arturgvieira-zz commentedon Jun 13, 2017
@refack Ok, also I wanted to run some code by you. Here is a short version of the cluster/master.js file https://gist.github.com/arturgvieira/493772fb633acfb1c8dcaba2d94cfa12
I made the changes above but not sure where to go from here.
arturgvieira-zz commentedon Jun 14, 2017
You mentioned on 'exit' to track the release of the
ids, I think that is what I'll do next.refack commentedon Jun 14, 2017
Yes, commented just that on the gist.
doc: fixes in cluster.md
test: reduce offset in test-inspector-port-cluster
cluster: overriding inspector port
doc: fixes in cluster.md
test: reduce offset in test-inspector-port-cluster
cluster: overriding inspector port
doc: fixes in cluster.md
test: reduce offset in test-inspector-port-cluster
cluster: overriding inspector port