-
Notifications
You must be signed in to change notification settings - Fork 28.7k
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
Scripts are sent in a non-existent executionContextId
#47438
Comments
This was a race that was exposed because we were waiting for scripts in the stacktrace to come in. Turns in Node.js doesn't emit `Runtime.executionContextCreated` for its first context. Refs nodejs/node#47438 Fixes #1643
This was a race that was exposed because we were waiting for scripts in the stacktrace to come in. Turns in Node.js doesn't emit `Runtime.executionContextCreated` for its first context. Refs nodejs/node#47438 Fixes #1643
Pull request welcome. What probably needs to happen is a call to
See also |
I think this indeed could be the issue here, I think this is a relevant comment I found while looking through the code: Lines 180 to 183 in 67fdb74
note that running test code only shows that the code involving primordials doesnt have correct Thank You! |
So, I'm not 100% sure, but I think it can be fixed by calling ContextCreated() after the snapshot has been deserialized with |
IIUC ContextCreated() already seems to be called no? Lines 452 to 469 in 67fdb74
here after creating context from snapshot we call Line 818 in 67fdb74
which should call contextCreated? is there any other place we should call it again? |
It calls it too early. CreateEnvironment() calls InitializeMainContext() - which calls AssignToContext() - before the inspector agent is started. |
ok I tried something like this diff --git a/src/api/environment.cc b/src/api/environment.cc
index c9bb4bdf16..6804ee6f90 100644
--- a/src/api/environment.cc
+++ b/src/api/environment.cc
@@ -478,6 +478,8 @@ Environment* CreateEnvironment(
env->InitializeInspector({});
}
}
+ std::cout << "context created" << std::endl;
+ env->inspector_agent()->ContextCreated(context, ContextInfo(""));
#endif
if (!use_snapshot && env->principal_realm()->RunBootstrapping().IsEmpty()) {
diff --git a/src/env.cc b/src/env.cc
index 571a8ed5ce..4b134a8a47 100644
--- a/src/env.cc
+++ b/src/env.cc
@@ -582,10 +582,6 @@ void Environment::AssignToContext(Local<v8::Context> context,
// This must not be done before other context fields are initialized.
ContextEmbedderTag::TagNodeContext(context);
-#if HAVE_INSPECTOR
- inspector_agent()->ContextCreated(context, info);
-#endif // HAVE_INSPECTOR
-
this->async_hooks()->InstallPromiseHooks(context);
TrackContext(context);
}
diff --git a/src/node.cc b/src/node.cc
index 66b7ef5ec5..f35b4d81a8 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -199,7 +199,7 @@ void Environment::InitializeInspector(
if (inspector_agent_->options().break_node_first_line) {
inspector_agent_->PauseOnNextJavascriptStatement("Break at bootstrap");
}
-
+ std::cout << "Inspector started" << std::endl;
return;
}
#endif // HAVE_INSPECTOR (some couts to track things) the output now looks like this Inspector started
context created
Runtime.executionContextCreated
{
method: 'Runtime.executionContextCreated',
params: {
context: {
id: 2,
origin: '',
name: '',
uniqueId: '2734271943675504607.6360033039428185957',
auxData: [Object]
}
}
}
Runtime.executionContextCreated
{
method: 'Runtime.executionContextCreated',
params: {
context: {
id: 1,
origin: '',
name: 'out/Release/node[54719]',
uniqueId: '-9125050196401512131.4619138934371537908',
auxData: [Object]
}
}
}
Runtime enabled
Debugger.scriptParsed
{
method: 'Debugger.scriptParsed',
params: {
scriptId: '6',
url: 'node:internal/per_context/primordials',
startLine: 0,
startColumn: 0,
endLine: 737,
endColumn: 0,
executionContextId: 0,
hash: 'bc07b5754e60d05f0e36aee626f46b4561cc1d342c7c84e1655eca736753f7f8',
isLiveEdit: false,
sourceMapURL: '',
hasSourceURL: false,
isModule: false,
length: 21457,
stackTrace: { callFrames: [Array] },
scriptLanguage: 'JavaScript',
embedderName: 'node:internal/per_context/primordials'
}
}
Got script in execution context 0, but have only 2,1
Debugger.scriptParsed
{
method: 'Debugger.scriptParsed',
params: {
scriptId: '431',
url: 'node:internal/modules/esm/handle_process_exit',
startLine: 0,
startColumn: 0,
endLine: 14,
endColumn: 0,
executionContextId: 2,
hash: '84163086c39d7e2b604473cf0a4d87c61ccf8d210cfbac4336bfb23348612f6f',
executionContextAuxData: { isDefault: false },
isLiveEdit: false,
sourceMapURL: '',
hasSourceURL: false,
isModule: false,
length: 424,
stackTrace: { callFrames: [Array] },
scriptLanguage: 'JavaScript',
embedderName: 'node:internal/modules/esm/handle_process_exit'
}
} One more executionId in the mix somehow? |
So far no success, tried to debug why #47438 (comment), overall can't really understand the flow additional contexts are coming out of and somehow the original '0' executionId also comes in 😕😓 |
I got a report of a behavior that I can't work around and may have the same root cause: #51067 |
Look into this today, seems the
I don't see a way to associate the main context id to the snapshot scripts with whatever API is available today in V8. Seems like it needs to be a feature request in V8 ? |
Also, #51067 is indeed related to the issue. Without being able to associate the main context execution id to the snapshot scripts the value of the mappings to retrieve the relevant |
Seems like the case for debugging scripts in embedded snapshots was discussed https://bugs.chromium.org/p/v8/issues/detail?id=9029 and is still an open issue. I think there is possibility to fix this in upstream. |
Version
19.8.1
Platform
Darwin MacBook-Pro-2.guest.corp.microsoft.com 22.4.0 Darwin Kernel Version 22.4.0: Mon Mar 6 21:00:17 PST 2023; root:xnu-8796.101.5~3/RELEASE_X86_64 x86_64
Subsystem
inspector
What steps will reproduce the bug?
Run the following script:
How often does it reproduce? Is there a required condition?
100% of the time
What is the expected behavior? Why is that the expected behavior?
The script should run successfully. All execution contexts should come in
Runtime.executionContextCreated
events beforeRuntime.enable
returns.What do you see instead?
Additional information
Later scripts are in the execution context ID of 1, but earlier ones are in the non-existent 0 context.
Originally came up in vscode-js-debug as a result of adding more intended correctness around how execution contexts are handled microsoft/vscode-js-debug#1643
The text was updated successfully, but these errors were encountered: