-
Notifications
You must be signed in to change notification settings - Fork 30k
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
lib: guard inspector console using process var #15008
Conversation
lib/internal/bootstrap_node.js
Outdated
console.timeEnd; | ||
console.trace; | ||
console.warn; | ||
if (process.config.v8_enable_inspector) { |
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 would be nice to move that condition up in the former if
.
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.
Sounds good, I'll move it. Thanks
17a73ac
to
b17c383
Compare
lib/internal/bootstrap_node.js
Outdated
@@ -54,7 +54,7 @@ | |||
NativeModule.require('internal/process/warning').setup(); | |||
NativeModule.require('internal/process/next_tick').setup(); | |||
NativeModule.require('internal/process/stdio').setup(); | |||
if (browserGlobals) { | |||
if (browserGlobals && process.config.v8_enable_inspector) { |
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 think the name is actually process.config.variables.v8_enable_inspector
?
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.
You are right, can't believe I missed that. 😞 Will update now. Thanks again!
You asked for the reason - If I am correct |
Thanks! Should we then perhaps do something like the following to still allow for the eager instantiation to happen: if (browserGlobals) {
if (!process.config.variables.v8_enable_inspector) {
NativeModule.require('module');
}
// Instantiate eagerly in case the first call is under stack overflow
// conditions where instantiation doesn't work.
const console = global.console;
console.assert;
console.clear;
console.count;
console.countReset;
console.dir;
console.error;
console.log;
console.time;
console.timeEnd;
console.trace;
console.warn;
} |
I would say let us wait for #15111. It should actually also solve the issue here and allow the eager instantiation. I do like the variable part a lot though and I guess it makes sense to switch the inspector check in the mentioned PR to this check instead. |
@danbev the mentioned PR just landed. I guess the issue itself should already be fixed but right now the inspector is always "loaded" and it is checked if it actually returns anything or not. Therefore it would still be nice to use |
@BridgeAR Sorry about the late reply (was at a f2f last week and had limited time). I'll take another look into this issue now. Thanks |
436dd13
to
87b1b97
Compare
Rebased and updated CI: https://ci.nodejs.org/job/node-test-pull-request/10249/ |
@@ -319,10 +319,10 @@ | |||
} | |||
|
|||
function setupInspector(originalConsole, wrappedConsole, Module) { | |||
const { addCommandLineAPI, consoleCall } = process.binding('inspector'); | |||
if (!consoleCall) { | |||
if (!process.config.variables.v8_enable_inspector) { |
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.
Depending on process.config
is dangerous because there are userland modules that completely replace it. During bootstrap it should be safe but problems still could come up.
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.
If it ever becomes an issue, we could cache it before user code runs.
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.
Or use process.binding('config')
as a stable alternative.
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 @cjihrig Thanks, I had not thought about that being an issue and I'm trying to understand how this might happen.
Using process.binding('config')
will give access to the builtin module config
, but as far as I can tell the information from config.gypi is provided as a native module (via node_js2c). The process object is then configured with that information in setupConfig which is called by node_bootstrap.js start function.
setupConfig
deletes the config from the _source and then sets these properties on the process object. Since it deletes the _source this function cannot be called multiple times, for example if it did not we could have done the same thing again.
What I'm having some difficulties understand is that how could a userland module be able to replace this at this stage. Would someone be able to shed some light on this?
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.
Userland code might not be able to replace process.config
by this stage, I haven't tested it. What I do know is that we've had issues depending on process.config
in later stages elsewhere in the code and we if we are going to use it here then we need to be certain that it won't be a problem. If there is no userland code that can be run before bootstrap gets to this point, then it should be ok.
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 still very early in the bootstrap process and I do not think it is possible to change it at that stage. To be on the safe side we could just add a test for it though.
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.
87b1b97
to
5a94460
Compare
const assert = require('assert'); | ||
assert.strictEqual(process.config.variables.v8_enable_inspector, 1); | ||
process.config.variables.v8_enable_inspector = 100; | ||
assert.strictEqual(process.config.variables.v8_enable_inspector, 100); |
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 am not sure if this is a appropriate test.
I would have expected the v8_enable_inspector
variable to be set to something falsy because we test it to be truthy and afterwards to check if the inspector is set up nevertheless.
Another approach would be to test that inspector is set without any variable manipulation. That should already verify that manipulating it has no impact on this anymore.
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.
@BridgeAR Thanks, I've updated the test. When going through the code I looks like any user land code will be call by Module.runMain, at which point the checking of process.config.variables.v8_enable_inspector done by bootstrap_node.js has already been performed. This also holds true for any preloaded modules. So as far as I can tell the check should be safe unless there are other ways this could happen that I've not taken into account.
@BridgeAR Would you mind taking another look at this now and see what you thing? Thanks |
@BridgeAR ping |
const assert = require('assert'); | ||
assert.strictEqual(process.config.variables.v8_enable_inspector, 1); | ||
process.config.variables.v8_enable_inspector = null; | ||
assert.strictEqual(process.config.variables.v8_enable_inspector, null); |
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.
How do we know here that the inspector is indeed set up properly (I would have expected to test for inspector specific functions or similar)? That is the most important part out of my perspective. As soon as we know that the inspector is set up, we do not even have to manipulate the variable anymore, because it would not have any effect afterwards.
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.
@BridgeAR Thanks for the feedback. I'm not working for a few days but will take another look at this next week.
Thank you for adding the test, but I'm not quite sure it's enough. The earliest user code that can run would be a preload module using |
6c47862
to
9395fca
Compare
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.
Still LGTM.
Currently the inspector module is always loaded and if it does not return anything the inspector console setup is skipped. This commit uses the process.config.variables.v8_enable_inspector variable to only load the inspector module if it is enabled.
9395fca
to
87f3f91
Compare
Landed in 1aac4c1 |
Currently the inspector module is always loaded and if it does not return anything the inspector console setup is skipped. This commit uses the process.config.variables.v8_enable_inspector variable to only load the inspector module if it is enabled. PR-URL: #15008 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
Currently the inspector module is always loaded and if it does not return anything the inspector console setup is skipped. This commit uses the process.config.variables.v8_enable_inspector variable to only load the inspector module if it is enabled. PR-URL: #15008 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
Currently the inspector module is always loaded and if it does not return anything the inspector console setup is skipped. This commit uses the process.config.variables.v8_enable_inspector variable to only load the inspector module if it is enabled. PR-URL: #15008 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
Currently the inspector module is always loaded and if it does not
return anything the inspector console setup is skipped.
This commit uses the process.config.variables.v8_enable_inspector
variable to only load the inspector module if it is enabled.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
lib