Skip to content

Commit 2ecd828

Browse files
khanayan123claude
andcommitted
fix: add mutex to root session ID singleton for thread safety
Protect concurrent set() calls with std::mutex, matching the codebase's standard pattern for shared state protection. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 881addf commit 2ecd828

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/datadog/root_session_id.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "root_session_id.h"
22

3+
#include <mutex>
4+
35
namespace datadog {
46
namespace tracing {
57
namespace root_session_id {
@@ -11,9 +13,15 @@ std::string& instance() {
1113
return id;
1214
}
1315

16+
std::mutex& mutex() {
17+
static std::mutex m;
18+
return m;
19+
}
20+
1421
} // namespace
1522

1623
void set(const std::string& id) {
24+
std::lock_guard<std::mutex> lock(mutex());
1725
if (instance().empty()) {
1826
instance() = id;
1927
}

0 commit comments

Comments
 (0)