-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
cluster: forked children eagerly ignore/replace inspect port from cluster settings #21853
Comments
While circling back on this, I was looking into the history on that file in the cluster module, and it looks like this behavior was added in 05707a9 (from #14140) by @mutantcornholio and committed by @Fishrock123 back on July 10, 2017, which means it's new for 8.x. I wonder if either of them have any thoughts on my thoughts, above? As a quick TL;DR, since this will go with the email notification: Even if a worker process is configured with a port already, as Also, the documentation is unclear on the precedence of the various |
Seems like the rule is "last one wins". Maybe we should clear that out in docs, yeah.
Am I getting your problem right? You want to set |
@mutantcornholio Thanks for the reply. If you check out the code example at the top of the issue, that should show what the intention is. I want to propagate the "debug state" from the master to the worker with a port of my choosing. I'm doing that by doing (fairly similar to your code) detection on the args of the master, then adding The problem is that that also triggers the detection you added, which doesn't consider the port I've already set. All of that is described in much more detail in the main, issue, though; so, I don't want to keep talking in case I contradict myself in some later restating 😁. |
The Setup
Here's a small example that can be used to show this behavior:
In this example, when the master process has been started with any of the
--inspect
arguments, we want to start the worker with the inspector active on a specific port. Here's some example output:What can be seen, here, is that the worker is forked with the configured argument from the cluster options'
execArgv
; but, the--inspect-port=10002
argument is also present, though it wasn't configured.The References
The
cluster
Module CodeThe code that does this appears to be the
createWorkerProcess(id, env)
function at /lib/internal/cluster/master.js:101. From this, we can see that this behavior appears to be intentional, at least as far as what the code says. Here's what I read from there:execArgv
arguments look like--inspect
,--inspect-brk
,--inspect-port
or--debug-port
...inspectPort
is defined in the cluster settings...inspectPort
.inspectPort
.`--inspect-port=${inspectPort}`
into the worker'sexecArgv
array.The Documentation
In the CLI docs, all three of
--inspect
,--inspect-brk
and--inspect-port
are indicated to support the[=[host:]port]
value. However, conceptually, based on what they each do, it seems like they would never be used together.In the
cluster
docs,settings.inspectPort
is indicated to set the inspect port of the worker.The Problems
So, here are the problems, as I see them:
settings.inspectPort
would allow one to configure the inspect port; however, that setting is completely ignored unlessexecArgv
already has one of the inspect arguments present (which could be--inspect-port
, resulting in two of the same argument).execArgv
, the selectedinspectPort
value ultimately results in the addition of the--inspect-port
option; however, in the documentation, that argument is indicated to only configure what the inspect port will be when/if inspection is latently activated.cluster
code explicitly combines them by intentionally adding--inspect-port
when it knows there's already an inspect argument present.Ultimately, the only option one has to be able to configure the inspect port for a worker is to both (1) add one of the inspect arguments and (2) set the
settings.inspectPort
. This will result inexecArgv
having something like--inspect --inspect-port=####
. In that case, one might as well leave off the port from the original argument as it will be overridden by the added one.All of this is fairly confusing to me. Why would the
cluster
code intentionally combine inspect arguments? If there is a precedence, it's opaque (i.e. it's not indicated in the documentation). Is this operating as expected? Am I just missing something and thinking about this "wrong"?P.S. The code for this in 10.x, while it has received some changes, does still appear to exhibit this behavior -- though I have not tested it myself.
The text was updated successfully, but these errors were encountered: