diff options
Diffstat (limited to 'src/env.cc')
-rw-r--r-- | src/env.cc | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/env.cc b/src/env.cc index 5da673b3e0..383df37aab 100644 --- a/src/env.cc +++ b/src/env.cc @@ -128,11 +128,22 @@ void InitThreadLocalOnce() { } void Environment::TrackingTraceStateObserver::UpdateTraceCategoryState() { + if (!env_->is_main_thread()) { + // Ideally, we’d have a consistent story that treats all threads/Environment + // instances equally here. However, tracing is essentially global, and this + // callback is called from whichever thread calls `StartTracing()` or + // `StopTracing()`. The only way to do this in a threadsafe fashion + // seems to be only tracking this from the main thread, and only allowing + // these state modifications from the main thread. + return; + } + env_->trace_category_state()[0] = *TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( TRACING_CATEGORY_NODE1(async_hooks)); Isolate* isolate = env_->isolate(); + HandleScope handle_scope(isolate); Local<Function> cb = env_->trace_category_state_function(); if (cb.IsEmpty()) return; @@ -182,7 +193,7 @@ Environment::Environment(IsolateData* isolate_data, AssignToContext(context, ContextInfo("")); if (tracing::AgentWriterHandle* writer = GetTracingAgentWriter()) { - trace_state_observer_.reset(new TrackingTraceStateObserver(this)); + trace_state_observer_ = std::make_unique<TrackingTraceStateObserver>(this); v8::TracingController* tracing_controller = writer->GetTracingController(); if (tracing_controller != nullptr) tracing_controller->AddTraceStateObserver(trace_state_observer_.get()); |