-
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
Segfault Creating Node Environments in v12.16.2 #33800
Comments
fe1ac49, the preceding commit, cleans up the code base to handle a nullptr It's possible I missed something or that something went wrong during back-porting. However, node/src/tracing/trace_event.cc Lines 16 to 18 in 3443e3a
Can you check if it works for you when you rewrite that method to this? TracingController* TraceEventHelper::GetTracingController() {
if (g_agent == nullptr) return nullptr;
return g_agent->GetTracingController();
} |
That gets a bit further but crashes when accessing the tracing controller
|
I think node/src/tracing/trace_event.h Lines 490 to 494 in 278aae2
nullptr check, along with a number of other places in the tracing code.
I’ll put a PR together, but if you are looking for a somewhat straightforward workaround, you should be able to create a |
@frutiger Can you try this patch and see if it works for you? diff --git a/src/tracing/trace_event.h b/src/tracing/trace_event.h
index be2276a9e276..2a79c5bc05b5 100644
--- a/src/tracing/trace_event.h
+++ b/src/tracing/trace_event.h
@@ -70,8 +70,7 @@ enum CategoryGroupEnabledFlags {
// const uint8_t*
// TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(const char* category_group)
#define TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED \
- node::tracing::TraceEventHelper::GetTracingController() \
- ->GetCategoryGroupEnabled
+ node::tracing::TraceEventHelper::GetCategoryGroupEnabled
// Get the number of times traces have been recorded. This is used to implement
// the TRACE_EVENT_IS_NEW_TRACE facility.
@@ -115,9 +114,10 @@ enum CategoryGroupEnabledFlags {
// const uint8_t* category_group_enabled,
// const char* name,
// uint64_t id)
-#define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \
- node::tracing::TraceEventHelper::GetTracingController() \
- ->UpdateTraceEventDuration
+#define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \
+ if (auto controller = \
+ node::tracing::TraceEventHelper::GetTracingController()) \
+ controller->UpdateTraceEventDuration
// Adds a metadata event to the trace log. The |AppendValueAsTraceFormat| method
// on the convertable value will be called at flush time.
@@ -319,6 +319,13 @@ class NODE_EXTERN TraceEventHelper {
static Agent* GetAgent();
static void SetAgent(Agent* agent);
+
+ static inline const uint8_t* GetCategoryGroupEnabled(const char* group) {
+ v8::TracingController* controller = GetTracingController();
+ static const uint8_t disabled = 0;
+ if (UNLIKELY(controller == nullptr)) return &disabled;
+ return controller->GetCategoryGroupEnabled(group);
+ }
};
// TraceID encapsulates an ID that can either be an integer or pointer. Pointers
@@ -467,6 +474,7 @@ static inline uint64_t AddTraceEventImpl(
// DCHECK(num_args, 2);
v8::TracingController* controller =
node::tracing::TraceEventHelper::GetTracingController();
+ if (controller == nullptr) return 0;
return controller->AddTraceEvent(phase, category_group_enabled, name, scope, id,
bind_id, num_args, arg_names, arg_types,
arg_values, arg_convertibles, flags);
@@ -489,6 +497,7 @@ static V8_INLINE uint64_t AddTraceEventWithTimestampImpl(
// DCHECK_LE(num_args, 2);
v8::TracingController* controller =
node::tracing::TraceEventHelper::GetTracingController();
+ if (controller == nullptr) return 0;
return controller->AddTraceEventWithTimestamp(
phase, category_group_enabled, name, scope, id, bind_id, num_args,
arg_names, arg_types, arg_values, arg_convertables, flags, timestamp); |
Also, based on #28724 Electron has run into this problem as well, so it might make sense to provide an official API for explicitly setting the |
Thanks @addaleax that seems to work for me. I had to tweak the patch a tiny bit as it did not cleanly apply on v12.16.2 3443e3a, but otherwise it worked (along with the patch from @bnoordhuis). Would this make sense to include in a release, or should I patch my builds of NodeJS? |
We added a hack for this a while ago for Electron, so let’s remove that hack and make this an official API. Refs: nodejs#28724 Refs: nodejs#33800
We added a hack for this a while ago for Electron, so let’s remove that hack and make this an official API. Refs: #28724 Refs: #33800 PR-URL: #33850 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
We added a hack for this a while ago for Electron, so let’s remove that hack and make this an official API. Refs: #28724 Refs: #33800 PR-URL: #33850 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
We added a hack for this a while ago for Electron, so let’s remove that hack and make this an official API. Refs: #28724 Refs: #33800 PR-URL: #33850 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
We added a hack for this a while ago for Electron, so let’s remove that hack and make this an official API. Refs: #28724 Refs: #33800 PR-URL: #33850 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
What steps will reproduce the bug?
I have a program that manages its own V8 Isolate, UV Event Loop and Node Environments. In Node 12.13.1, it was possible to initialize a V8 Platform via
node::InitializeV8Platform(...)
that would provide all that was expected of Node Contexts. I am trying to upgrade to Node 12.16.2, but this function was removed in d77a1b0.I am looking for a minimal example that allows successful creation of a Node Environment object. To reproduce:
configure
thenmake
test.cc
(I omitted cleanup for brevity):lldb
; you should see the following segfault:This is happening because the tracing controller has not been set; as far as I can see, this is only possible to set via the public APIs using a method such as
node::Start
, but that is not very friendly for programs that wish to create multiple environments. It's very likely that I have missed something in how to properly create these environments, any pointers are appreciated.How often does it reproduce? Is there a required condition?
This should be a universal issue when attempting to create environments against Node v12.16.2.
What is the expected behavior?
I would expect the environment to be created, and the context to be usable to execute JavaScript.
What do you see instead?
A segmentation fault.
The text was updated successfully, but these errors were encountered: