Repository navigation
Fix crash when process exits with a live Tracer in a static wrapper - #398
Conversation
BenchmarksBenchmark execution time: 2026-11-10 20:22:22 Comparing candidate commit 2d90c78 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 8 metrics, 0 unstable metrics.
|
17c014e to
b5e2652
Compare
b5e2652 to
a356d8e
Compare
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
left a comment
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a356d8eddc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
left a comment
There was a problem hiding this comment.
The new shutdown regression test fails when the build directory contains spaces because its helper path is passed unquoted to the shell. A localized shell-escaping replacement was verified.
🤖 Bits Code Review · Commit a356d8e
a356d8e to
7bcb122
Compare
left a comment
There was a problem hiding this comment.
The singleton lifetime fix appears sound, but the new shutdown test fails when the build directory contains spaces because its helper path is passed unquoted to a shell.
🤖 Bits Code Review · Commit 7bcb122
…es and special characters
left a comment
There was a problem hiding this comment.
The PR keeps the process-context singleton alive to prevent shutdown crashes with statically wrapped tracers and adds a subprocess regression test. The update fixes helper paths containing spaces, but quoting remains incomplete: an apostrophe in the build path still prevents the helper from running, leaving one open test defect.
🤖 Bits Code Review · Commit 2d90c78
Overview
Fix a (rare) crash when a process exits with a
Tracerinstance that lives in a static wrapper, by, on purpose, never destroy theStaticOtelCtxStatesingleton.Motivation
This is a hardening following DataDog/nginx-datadog#483. The problem was detected in the Datadog Nginx module, and fixed there by avoiding constructing a
Tracerin processes where it is not needed, but the problem can still appear in another context.Additional Notes
Detailed Bug Description
The
Tracerconstructor callsTracer::store_config()which callsOtelCtxRegistration::publish()which callsget_otel_ctx_state().get_otel_ctx_state()instantiates astaticStaticOtelCtxState.OtelCtxRegistration::publish()returns aunique_ptr<OtelCtxRegistration>, stored as a member ofTracer.The
OtelCtxRegistrationdestructor also callsget_otel_ctx_state().When instantiating a
Tracer, theStaticOtelCtxState's construction finishes before theTracer's one. So, even if theTracerisstatic, it is destroyed before theStaticOtelCtxState, which is fine.But if one creates an empty
static optional<Tracer>, and later fills it, theoptional<Tracer>finishes construction first. So it will be destroyed after the staticStaticOtelCtxState, which causes an issue because theTracerdestructor then tries to access the already destroyedStaticOtelCtxState.Test
The new test needs a dedicated executable that reproduces the situation described above (a
Tracerinstance that lives in a static wrapper) and that is independent from other tests.Without the fix, the new test fails as expected: https://github.com/DataDog/dd-trace-cpp/actions/runs/42879768486/job/130053552161?pr=398.
References
Jira ticket: IDMPL-1237: [C++ Tracer] Tracer - StaticOtelCtxState destruction order issue.
Contributor Checklist