From 8908b830b1f3c4b7bc33d25393b99d59f754038f Mon Sep 17 00:00:00 2001 From: Gregory LEOCADIE Date: Thu, 25 Jul 2024 16:07:49 +0200 Subject: [PATCH] Signal-based profiler/Non-Signal-based: prevent deadlock --- .../LinuxStackFramesCollector.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/profiler/src/ProfilerEngine/Datadog.Profiler.Native.Linux/LinuxStackFramesCollector.cpp b/profiler/src/ProfilerEngine/Datadog.Profiler.Native.Linux/LinuxStackFramesCollector.cpp index e5aa1ad12277..0cbd01b86d80 100644 --- a/profiler/src/ProfilerEngine/Datadog.Profiler.Native.Linux/LinuxStackFramesCollector.cpp +++ b/profiler/src/ProfilerEngine/Datadog.Profiler.Native.Linux/LinuxStackFramesCollector.cpp @@ -97,8 +97,6 @@ StackSnapshotResultBuffer* LinuxStackFramesCollector::CollectStackSampleImplemen // Otherwise, the CPU consumption to collect the callstack, will be accounted as "user app CPU time" auto timerId = pThreadInfo->GetTimerId(); - _plibrariesInfo->UpdateCache(); - if (selfCollect) { // In case we are self-unwinding, we do not want to be interrupted by the signal-based profilers (walltime and cpu) @@ -106,6 +104,8 @@ StackSnapshotResultBuffer* LinuxStackFramesCollector::CollectStackSampleImplemen // This lock is acquired by the signal-based profiler (see StackSamplerLoop->StackSamplerLoopManager) pThreadInfo->GetStackWalkLock().Acquire(); + _plibrariesInfo->UpdateCache(); + on_leave { pThreadInfo->GetStackWalkLock().Release(); @@ -143,6 +143,8 @@ StackSnapshotResultBuffer* LinuxStackFramesCollector::CollectStackSampleImplemen } }; + _plibrariesInfo->UpdateCache(); + std::unique_lock stackWalkInProgressLock(s_stackWalkInProgressMutex); const auto threadId = static_cast<::pid_t>(pThreadInfo->GetOsThreadId());