← Back to Pull requests

test(profiling): suppress TSan false positive in fork death tests #21997

Closed
unknown closed this pull request without merging on Nov 20, 2026 20:56 UTC
View on GitHub
unknown unknown commented on Nov 20, 2026 19:40 UTC
Author

<!-- dd-meta {"pullId":"e5ea62b1-f454-4ef8-8f18-f556cd5e43d1","source":"chat","resourceId":"3791bbb8-f9f4-41e3-a2e7-a94b71e38e67","workflowId":"0938f146-e4ef-4e87-b9cb-dde01bbc3fe7","codeChangeId":"0938f146-e4ef-4e87-b9cb-dde01bbc3fe7","sourceType":"code_channel"} -->

Description

The ForkDeathTest native tests in ddtrace/internal/datadog/profiling/dd_wrapper/test/test_forking.cpp fail now and then on main in the profiling_native ThreadSanitizer (thread) jobs. All five tests are affected, not only SampleInThreadsAndForkManyFast, and only under TSan. Over the last 30 days they failed 12 times out of about 4,800 TSan runs. The death-test process exits with status 66, TSan's exit code after it prints a report, so JUnit only records "Failed".

Every failure is the same report, in the parent process:

WARNING: ThreadSanitizer: data race
  Write of size 8 by thread T1 (mutexes: write M0):        <- upload thread
    #0 close
    #1 core::ptr::drop_glue::<tokio::runtime::driver::Handle>
    #2 ddup_upload
  Previous read of size 8 by main thread:
    #0 write
    #1 <std::sys::fd::unix::FileDesc>::write
    ...
    #4 Datadog::ProfilerState::start() lambda              <- prefork handler
    #6 __run_prefork_handlers
  Location is file descriptor 6 created by thread T1 at:
    #0 eventfd
    #1 mio waker <- tokio::runtime::io::driver <- ddup_upload

The test forks while an upload is in flight. ProfilerState::prefork() cancels that upload from the forking thread. The cancellation wakes the exporter's single-threaded tokio runtime by writing to its eventfd. The upload thread then returns and drops the exporter, which closes the eventfd.

This is not a real race. The waker holds a reference to the runtime handle, and the eventfd is only closed when the last reference is dropped, so the close always comes after the write. That ordering uses atomics in libdatadog's Rust code, which is not built with TSan, so TSan cannot see it. TSan only sees an ordering when the upload thread wakes up from epoll_wait after the write, because it treats that as synchronization through the epoll file descriptor. When the upload thread notices the cancellation another way, which happens more often on a busy runner, TSan reports a race on the file descriptor.

The existing entries in TSan.supp cover the same kind of false positive ("libdd is not compiled with sanitizers"). This PR adds one narrow entry, race:tokio::runtime::driver::Handle, for reports where tokio's runtime driver handle is dropped. There are no production code changes.

Testing

Reproduced in the profiling_native CI image (Python 3.10, build_standalone.sh --thread RelWithDebInfo stack_test). I ran test_forking --gtest_filter=ForkDeathTest.* in 10 parallel loops on 5 CPUs to mimic a busy runner:

  • Before: 19 of 351 runs failed (1,755 test executions). Every failure had the report above.

  • After: 0 TSan reports in 400 runs (2,000 test executions).

  • I also ran the same scenario 300 times outside gtest with print_suppressions=1. The new entry matched in 8 runs, which confirms it is what absorbs the report, and no unsuppressed report was printed.

  • With the change, ctest in the dd_wrapper TSan build passes: 26 tests, OOM test skipped as usual.

  • scripts/lint checks passes.
  • Risks

    Low, test-only. TSan will hide any race report with a tokio runtime driver handle drop in its stack. A real race in that drop would be hidden too, but TSan cannot check libdatadog's Rust code anyway.

    Additional Notes

  • During the stress runs I also saw a rare hang that this PR does not fix: 6 times in about 1,050 runs on the overloaded runner. The forked child stalls inside TSan's runtime while it starts the sampler threads, after a fork during which the upload thread was still alive. TSan says starting threads after a multi-threaded fork is not supported, and runs it only because of die_after_fork=0. The CI failures above are not this hang: they finish in about 1.3 s, the same as passing runs, and exit with status 66.

  • sample_in_threads_and_fork still never starts its parent sampler threads (ids is empty), as #16153 noted. That is unchanged here.

  • No release note: this only changes the TSan suppressions used by the native tests.
  • ---

    PR by Bits - View session in Datadog • Open in Slack

    Comment @datadog to request changes

    Diff: 562 lines (+421 / -141) across 7 files Reviewer: gyuheon0h Review duration: 76m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 562 lines diff across 7 files
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.379
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #21997"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 49.7% (MEDIUM) · Higher = larger blast radius
    49.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.6% · Safe to merge
    19.6%