-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Fixed cluster inspect port logic #13619
Conversation
/cc @mcollina |
/cc @nodejs/testing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nits.
Would like more review from others.
src/node.cc
Outdated
// process._debugOptions | ||
Local<Object> debugOptions = Object::New(env->isolate()); | ||
READONLY_DONT_ENUM_PROPERTY(process, | ||
"_debugOptions", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments (don't fix then until we get more feedback)
- There is preference to have this in
src/node_constants.cc
but I'm not sure how easy that is to move it - I would call it
_cliDebugOptions
and addenabled
. - Maybe there's a more efficient way to set these since they are constants?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything in src/node_constants.cc
looks like something defined at compile time, therefore it's no place for these. You're sure about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#12949 (comment)
It's not trivial, so I deferred that move. I have no strong feeling about this, maybe someone else does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be in require('config')
, IIRC, not the node constants, right @jasnell ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please drop this off process.binding('config')
rather than adding a new property off process
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// The config binding is used to provide an internal view of compile or runtime
// config options that are required internally by lib/*.js code. This is an
// alternative to dropping additional properties onto the process object as
// has been the practice previously in node.cc.
I didn't know that! Yeah, ok, makes sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jasnell done
port = debuggerPort + offset++ * 10; | ||
|
||
spawnMaster({ | ||
execArgv: [`--inspect=[::]:${port}`], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this work? (before #13478 lands)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That depends on your definition of work :)
Yes, worker listens on ipv4 address, but that's not what I'm checking here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @nodejs/v8-inspector @mcollina |
I think this should be documented both in doc/api/cluster.md and in the website in the inspector tab. I have no time to try this out right now, but the code LGTM pending docs. |
@mcollina what exactly should be documented? Btw, if we're about to document inspect port incrementing behavior (or is it already somewhere in docs?)... P.S. could anyone run the CI please? |
|
||
spawnMaster({ | ||
execArgv: [`--inspect=${port}`], | ||
workers: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be fragile
Could you describe the issue, please? I'm not quite getting what's going wrong..
we get port collisions when doing port
+[1,2,3]
Port collisions between tests within single test run?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Port collisions between tests within single test run?
Yes. Probably will not be a problem if you use common.PORT
but if you use 0 the OS give other processes ports in that range. We're not sure to whom, maybe Jenkins communication, but we've seen port clashes not rarely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is relevant to sequential tests too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, unfortunatly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I suggested doing https://github.com/nodejs/node/pull/13373/files#diff-4b2a51d5cbf4c8edb50bfd0f7016bb84R16 And just close the workers immediately.
In a way it's actually a more specific test to your code changes (manipulating argv, rather than making sure the worker starts)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've looked at the test again and I don't think my case is relevant to yours.
Testing zero port + offset will be always dangerous because you can get port near some-constantly-occupied port.
With sequential tests that's the only case I've got in mind.
That case couldn't take place with common.PORT
+ offset because it would result in constant CI fails, not rare occasions.
Ignore ARM (Pi3) fail. CI is ✔️ @mutantcornholio You could document inspector port incrementing (Ref: #13343 (comment)) but since it wasn't changed by this PR, IMHO that's up to you. AFAICT this still overrides |
Yes, that will in next PR. After this gets to master. |
|
||
const assert = require('assert'); | ||
const cluster = require('cluster'); | ||
const common = require('../common'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
common
should be the first require.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
5867317
to
5a685d9
Compare
I think you may need to bring the check for Unless I am missing something, there is a subtle trade-off here. After your change:
But before:
I don't have an opinion on which set of pro-vs-con is better or worse, but changing the balance from one to the other could be seen as semver-major. Clearly @eugeneo's idea of using new inspect protocol features so that only the master listens on the debug port, and the workers communicate with the master and debug messages to them tunnel over one single TCP connection is the eat-your-cake-and-have-it-too solution, but that'll be a while coming. |
Other than the possible semver-majorness of this (which could probably be fixed with one regex test), I really like its simplicity, anything that does more with less code is 💯 by me. |
Yeah, I think you're right. That may be a problem. In our production, worker ids sometimes may go up to a 1K. |
I'm trying to figure this out also, but it seems to me that ports would increment for children anyway 🤔 (that's #12941) the user has no control over that... |
I think the debug port used to be incremented only in this case: node/lib/internal/cluster/master.js Line 109 in 9dc3f93
|
Instead of parsing execArgv, just adding --inspect-port with whatever debug port should be. Also exporting initial debug options to `process._debugOptions`, but needed it only in tests for now. parallel/test-cluster-inspector-debug-port.js deleted in favor of inspector/test-inspector-port-cluster.js Refs: nodejs#9659 (comment)
5a685d9
to
5e101d9
Compare
@sam-github done |
* Adding --inspect-port with debug port, instead of parsing `execArgv` * Export CLI debug options to `process.binding('config').debugOptions` (currently used only in tests) PR-URL: nodejs#13619 Refs: nodejs#9659 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
Landed in 2777a7e 🍾 |
Quick extra sanity on |
^_^ |
Thanks and congrats, @mutantcornholio! 🎉 |
* Adding --inspect-port with debug port, instead of parsing `execArgv` * Export CLI debug options to `process.binding('config').debugOptions` (currently used only in tests) PR-URL: #13619 Refs: #9659 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
* Adding --inspect-port with debug port, instead of parsing `execArgv` * Export CLI debug options to `process.binding('config').debugOptions` (currently used only in tests) PR-URL: #13619 Refs: #9659 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
While we have not been backporting most inspector changes, this looks potentially useful. Thoughts on backporting to v6.x? |
While I had problems making this work on 6.x (see #9659), it is possible to backport it. Don't know if it worth the trouble though. The problem was there at least since 4.x, maybe even 0.12. That, and you'll break the hack I'm using to set worker's debug port (#9659 (comment)) :D |
Even though this is not specifically an |
When using cluster and --inspect as cli argument it is correctly handled and each worker will use a different port, this was fixed by nodejs#13619. But when env var NODE_OPTIONS="--inspect" is set this logic doesn't apply and the workers will fail as they try to attach to the same port. Fixes: nodejs#19026
…k with NODE_OPTIONS="--inspect" When using cluster and --inspect as cli argument it is correctly handled and each worker will use a different port, this was fixed by nodejs#13619. But when env var NODE_OPTIONS="--inspect" is set this logic doesn't apply and the workers will fail as they try to attach to the same port. Fixes: nodejs#19026
When using cluster and --inspect as cli argument it is correctly handled and each worker will use a different port, this was fixed by #13619. But when env var NODE_OPTIONS="--inspect" is set this logic doesn't apply and the workers will fail as they try to attach to the same port. Fixes: #19026 PR-URL: #19165 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Richard Lau <[email protected]>
When using cluster and --inspect as cli argument it is correctly handled and each worker will use a different port, this was fixed by #13619. But when env var NODE_OPTIONS="--inspect" is set this logic doesn't apply and the workers will fail as they try to attach to the same port. Fixes: #19026 PR-URL: #19165 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Richard Lau <[email protected]>
This is first PR mentioned in
#9659 (comment)
Turned out, instead of parsing execArgv and deciding what port to use, we could just add
--inspect-port
to whatever port we calculated (thanks, @sam-github).I've exported initial debug options to
process._debugOptions
, but I need it only in tests for now.To test new cases (different host:port variations), I wrote new test
suite
inspector/test-inspector-port-cluster.js
and deletedparallel/test-cluster-inspector-debug-port.js
in favor ofit.
cluster.setupMaster
wasn't sufficient, I had actually start master process with debug arguments.(
parallel/test-cluster-inspector-debug-port.js
was still passing at the moment)Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
cc/ @refack @sam-github @Trott @bnoordhuis @cjihrig