From 4386d0227ca32a039b76ccdd29983909fed4c87d Mon Sep 17 00:00:00 2001 From: Attila Szegedi Date: Tue, 27 Jan 2026 16:55:46 +0100 Subject: [PATCH] Moved GC callback registration in StartImpl, to be symmetrical with their deregistration through StopImpl->Dispose. --- bindings/profilers/wall.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/bindings/profilers/wall.cc b/bindings/profilers/wall.cc index d605ff5f..1a028a88 100644 --- a/bindings/profilers/wall.cc +++ b/bindings/profilers/wall.cc @@ -774,11 +774,6 @@ WallProfiler::WallProfiler(std::chrono::microseconds samplingPeriod, jsArray_ = v8::Global(isolate, jsArray); std::fill(fields_, fields_ + kFieldCount, 0); - if (collectAsyncId_ || useCPED_) { - isolate->AddGCPrologueCallback(&GCPrologueCallback, this); - isolate->AddGCEpilogueCallback(&GCEpilogueCallback, this); - } - #if DD_WALL_USE_CPED if (useCPED_) { // Used to create CPED proxy objects that will have one internal field to @@ -976,6 +971,14 @@ Result WallProfiler::StartImpl() { return Result{"Cannot start profiler: another profiler is already active."}; } + // Register GC callbacks for async ID and CPED context tracking before + // starting profiling + auto isolate = Isolate::GetCurrent(); + if (collectAsyncId_ || useCPED_) { + isolate->AddGCPrologueCallback(&GCPrologueCallback, this); + isolate->AddGCEpilogueCallback(&GCEpilogueCallback, this); + } + profileId_ = StartInternal(); auto collectionMode = withContexts_ @@ -984,7 +987,6 @@ Result WallProfiler::StartImpl() { : CollectionMode::kNoCollect); collectionMode_.store(collectionMode, std::memory_order_relaxed); started_ = true; - auto isolate = Isolate::GetCurrent(); node::AddEnvironmentCleanupHook(isolate, &WallProfiler::CleanupHook, isolate); return {}; }