-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
inspector: split the HostPort being used and the one parsed from CLI #24772
Conversation
@@ -243,12 +243,12 @@ void Open(const FunctionCallbackInfo<Value>& args) { | |||
|
|||
if (args.Length() > 0 && args[0]->IsUint32()) { | |||
uint32_t port = args[0].As<Uint32>()->Value(); | |||
agent->options()->host_port.port = port; | |||
agent->host_port()->set_port(static_cast<int>(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.
The cast can overflow. Better to check that args[0]->IsInt32()
and that args[0]->Int32Value() > 0
.
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 was already possible to overflow before since we were assigning uint32_t to int anyways. I think we'd better turn port
into a uint16_t
(see the TODO in node_options.h
) and do the checks whenever we set it, but I'd prefer to do that in another patch, because the port is actually settable from user land so there will be a more obvious behavior change than in this patch. (I am also thinking about using gsl::narrow to do it but we will need to introduce GSL as a dependency first...or maybe we can simply mask that with 0xffff
)
env->options()->debug_options->host_port.port = | ||
value->Int32Value(env->context()).FromMaybe(0); | ||
int32_t port = value->Int32Value(env->context()).FromMaybe(0); | ||
env->inspector_host_port()->set_port(static_cast<int>(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.
Unnecessary cast, right?
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 guess it's better to be explicit than implicit? Also I plan to turn this into a uint16_t
in the future - I think that's also where things like GSL (see #23821) may be useful
// This is a copy of the debug options parsed from CI in the Environment. | ||
// Do not use the host_port in that, instead manipulate the shared host_port_ | ||
// pointer which is meant to store the actual host and port of the inspector | ||
// server. |
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's kind of gnarly to have those fields duplicated. Can that be fixed somehow?
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 tried a few approaches, e.g. splitting the options into two Options
subclasses instead of putting them in one DebugOptions
, that makes the parsing code even more complicated because we have combined arguments like --inspect-brk=127.0.0.1:0
. Also, the HostPort in DebugOptions are actually per-process (because those are parsed from CLI) whereas the shared HostPort are per-Environment (since the inspector agents are per-Environment). Conceptually, they are not really duplicates because the CLI ones are "snapshots" of the parsed arguments which may still be useful themselves (e.g. in tests)
Removed the unnecessary per-process lock in |
Added a few compile-time switches to make it build when inspector is not enabled (like before, that will result in all the debug options being default..I wonder whether we want to just eliminate them all in the future). CI: https://ci.nodejs.org/job/node-test-pull-request/19164/ |
@joyeecheung Looks like this might need a rebase? |
d926a7c
to
80abade
Compare
Resume Build CI: https://ci.nodejs.org/job/node-test-pull-request/19198/ ✔️ |
Instead of using a shared pointer of the entire debug option set, pass the parsed debug option to inspector classes by value because they are set once the CLI argument parsing is done. Add another shared pointer to HostPort being used by the inspector server, which is copied from the one in the debug options initially. The port of the shared HostPort is 9229 by default and can be specified as 0 initially but will be set to the actual port of the server once it starts listening. This makes the shared state clearer and makes it possible to use `require('internal/options')` in JS land to query the CLI options instead of using `process._breakFirstLine` and other underscored properties of `process` since we are now certain that these values should not be altered once the parsing is done and can be passed around in copies without locks.
80abade
to
c631a1a
Compare
Rebased. CI:https://ci.nodejs.org/job/node-test-pull-request/19288/ This needs one more approval to land. Can I have some reviews please? @nodejs/v8-inspector @nodejs/process @nodejs/build-files |
Resume: https://ci.nodejs.org/job/node-test-pull-request/19332/ (Only failure in the previous CI run was #24403 , though) |
Landed in 61a8963 |
Instead of using a shared pointer of the entire debug option set, pass the parsed debug option to inspector classes by value because they are set once the CLI argument parsing is done. Add another shared pointer to HostPort being used by the inspector server, which is copied from the one in the debug options initially. The port of the shared HostPort is 9229 by default and can be specified as 0 initially but will be set to the actual port of the server once it starts listening. This makes the shared state clearer and makes it possible to use `require('internal/options')` in JS land to query the CLI options instead of using `process._breakFirstLine` and other underscored properties of `process` since we are now certain that these values should not be altered once the parsing is done and can be passed around in copies without locks. PR-URL: #24772 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Instead of using a shared pointer of the entire debug option set, pass the parsed debug option to inspector classes by value because they are set once the CLI argument parsing is done. Add another shared pointer to HostPort being used by the inspector server, which is copied from the one in the debug options initially. The port of the shared HostPort is 9229 by default and can be specified as 0 initially but will be set to the actual port of the server once it starts listening. This makes the shared state clearer and makes it possible to use `require('internal/options')` in JS land to query the CLI options instead of using `process._breakFirstLine` and other underscored properties of `process` since we are now certain that these values should not be altered once the parsing is done and can be passed around in copies without locks. PR-URL: #24772 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Instead of using a shared pointer of the entire debug option set, pass the parsed debug option to inspector classes by value because they are set once the CLI argument parsing is done. Add another shared pointer to HostPort being used by the inspector server, which is copied from the one in the debug options initially. The port of the shared HostPort is 9229 by default and can be specified as 0 initially but will be set to the actual port of the server once it starts listening. This makes the shared state clearer and makes it possible to use `require('internal/options')` in JS land to query the CLI options instead of using `process._breakFirstLine` and other underscored properties of `process` since we are now certain that these values should not be altered once the parsing is done and can be passed around in copies without locks. PR-URL: nodejs#24772 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Instead of using a shared pointer of the entire debug option set,
pass the parsed debug option to inspector classes by value because
they are set once the CLI argument parsing is done. Add another shared
pointer to HostPort being used by the inspector server, which is copied
from the one in the debug options initially. The port of the shared
HostPort is 9229 by default and can be specified as 0 initially but
will be set to the actual port of the server once it starts listening.
This makes the shared state clearer and makes it possible to use
require('internal/options')
in JS land to query the CLI optionsinstead of using
process._breakFirstLine
and other underscoredproperties of
process
since we are now certain that thesevalues should not be altered once the parsing is done and can be
passed around in copies without locks.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes