Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

joyeecheung
Copy link
Member

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.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Dec 1, 2018
@joyeecheung joyeecheung added the inspector Issues and PRs related to the V8 inspector protocol label Dec 1, 2018
@joyeecheung
Copy link
Member Author

src/node_options.h Outdated Show resolved Hide resolved
src/inspector_agent.h Outdated Show resolved Hide resolved
@@ -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));
Copy link
Member

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.

Copy link
Member Author

@joyeecheung joyeecheung Dec 2, 2018

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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary cast, right?

Copy link
Member Author

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.
Copy link
Member

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?

Copy link
Member Author

@joyeecheung joyeecheung Dec 2, 2018

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)

src/node_process.cc Outdated Show resolved Hide resolved
@joyeecheung
Copy link
Member Author

Removed the unnecessary per-process lock in DebugPortGetter and DebugPortSetter since they are now per-Environment shared pointers.

CI: https://ci.nodejs.org/job/node-test-pull-request/19159/

@joyeecheung
Copy link
Member Author

joyeecheung commented Dec 3, 2018

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/

@addaleax
Copy link
Member

addaleax commented Dec 4, 2018

@joyeecheung Looks like this might need a rebase?

@joyeecheung
Copy link
Member Author

@Trott
Copy link
Member

Trott commented Dec 4, 2018

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.
@joyeecheung
Copy link
Member Author

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

@joyeecheung
Copy link
Member Author

@joyeecheung
Copy link
Member Author

Resume: https://ci.nodejs.org/job/node-test-pull-request/19332/

(Only failure in the previous CI run was #24403 , though)

@joyeecheung
Copy link
Member Author

Landed in 61a8963

@joyeecheung joyeecheung closed this Dec 8, 2018
joyeecheung added a commit that referenced this pull request Dec 8, 2018
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>
BethGriggs pushed a commit that referenced this pull request Dec 17, 2018
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>
@BethGriggs BethGriggs mentioned this pull request Dec 18, 2018
refack pushed a commit to refack/node that referenced this pull request Jan 14, 2019
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. inspector Issues and PRs related to the V8 inspector protocol lib / src Issues and PRs related to general changes in the lib or src directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants