Skip to content

test: fix load-dependent flake in nativeThreadNameRace_ut (wait for /proc task unhash before scans) - #979

Merged
jbachorik merged 2 commits into
mainfrom
fix-native-thread-name-race-flake
Nov 12, 2026
Merged

jbachorik merged 2 commits into
mainfrom
fix-native-thread-name-race-flake

Conversation

@jbachorik

Copy link
Copy Markdown
Collaborator

What does this PR do?:
Fixes a load-dependent flake in nativeThreadNameRace_ut.threadDyingBetweenScansIsNeverNamed on dd-gitlab/gtest-asan-amd64. After pthread_join, the test now polls until the exited thread's tid disappears from /proc/self/task before running the native-thread-name scan passes.

Motivation:
The test assumed pthread_join returning implies the tid is gone from /proc/self/task. The kernel does not guarantee that: pthread_join returns when the exiting thread clears clear_child_tid in exit_mm() (mm_release(), kernel/fork.c), but the tid stays listed until exit_notify() → release_task() → __unhash_process() unhashes it — a real window in which the tid is still listed with a readable inherited comm. On a throttled shared CI runner the dying thread can sit descheduled in that window while the joiner runs the test's passes; the dump-time pass (defer=false) then records the mid-exit tid under its inherited process comm, and the test sees "nativeThreadNam" instead of "".

Verification (exact CI build image, registry.ddbuild.io/ci/async-profiler-build@81eab385, linux/amd64):

  • Standalone probe of the kernel ordering: 462/50 000 joins caught the tid still visible after pthread_join returned, with the comm readable and equal to the process name on hits.
  • Fixed test binary: 400 sequential + 160 CPU-pressured runs, all pass (pre-fix qemu loop passed 300/300 as well — the window needs real multi-CPU contention, which the CI pod provides).

The pinned invariant is unchanged and now matches what the kernel guarantees: a thread invisible to the scans is never named. Naming a listed (mid-exit) thread is desirable production behavior — it is the refresher-pass gap filler for short-lived threads — so no product code changes.

Additional Notes:

  • The poll is bounded at 30 s (generous for throttled CI runners); on timeout it falls through so the existing EXPECT diagnoses the residual visibility.
  • Pre-existing test on main (d723d998d); not part of the open Add HotSpot layout-offset value cross-checks and ASan granule rounding #968 stack.
  • Agentic review (sphinx): 1 real LOW fixed (missing <stdio.h> include); the tid-reuse-during-poll finding was refuted by adjudication (tids allocate monotonically until pid_max wraparound, not eagerly recycled); the 30 s worst-case stall is accepted by design.

How to test the change?:

./.claude/commands/build-and-summarize :ddprof-lib:gtestDebug_nativeThreadNameRace_ut

and on CI: dd-gitlab/gtest-asan-amd64.

For Datadog employees:

  • If this PR touches code that signs or publishes builds or packages, or handles
    credentials of any kind, I've requested a security review (run the dd:platform-security-review
    skill, or file a request via the PSEC review form).
    bewaire also runs automatically on every PR.
  • This PR doesn't touch any of that.
  • JIRA: PROF-12574

@jbachorik jbachorik added the AI label Nov 11, 2026
@dd-octo-sts

dd-octo-sts Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

CI Test Results

Run: #43440990394 | Commit: 399ce5e | Duration: 3h 0m 18s (longest job)

✅ All 32 test jobs passed

Status Overview

JDK glibc-aarch64/debug glibc-amd64/debug musl-aarch64/debug musl-amd64/debug
8 - ✅ - -
8-ibm - ✅ - -
8-j9 ✅ ✅ - -
8-librca - - ✅ ✅
8-orcl - ✅ - -
11 - ✅ - -
11-j9 ✅ ✅ - -
11-librca - - ✅ ✅
17 ✅ 🚫 - -
17-graal ✅ ✅ - -
17-j9 ✅ ✅ - -
17-librca - - ✅ ✅
21 ✅ ✅ - -
21-graal ✅ ✅ - -
21-librca - - ✅ ✅
25 ✅ ✅ - -
25-graal ✅ ✅ - -
25-librca - - ✅ ✅

Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled

Summary: Total: 32 | Passed: 31 | Failed: 0 | Cancelled: 1


Updated: 2026-11-13 17:19:14 UTC

@dd-octo-sts

dd-octo-sts Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

✅ All 40 integration tests passed

📊 Dashboard · 👷 Pipeline · 📦 d3b94186

@datadog-prod-us1-6

This comment has been minimized.

@dd-octo-sts

dd-octo-sts Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Scan-Build Report

User:runner@runnervmwuk1x
Working Directory:/home/runner/work/java-profiler/java-profiler/ddprof-lib/src/test/make
Command Line:make -j4 all
Clang Version:Ubuntu clang version 21.1.8 (6ubuntu1)
Date:Wed Nov 11 16:59:06 2026

Bug Summary

Bug TypeQuantityDisplay?
All Bugs2
Logic error
Dereference of null pointer1
Unused code
Dead initialization1

Filter Results by File

Reports

Bug Group Bug Type ▾ File Function/Method Line Path Length
Unused codeDead initializationreferenceChains.cppapplyOomRamp4971
Logic errorDereference of null pointerperfEvents_linux.cppunregisterThread72026

@jbachorik
jbachorik marked this pull request as ready for review November 12, 2026 09:20
@jbachorik
jbachorik requested a review from a team as a code owner November 12, 2026 09:20
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T09:21:26.464818Z d3b9418 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@jbachorik
jbachorik merged commit 399ce5e into main Nov 12, 2026
281 of 301 checks passed
@jbachorik
jbachorik deleted the fix-native-thread-name-race-flake branch November 12, 2026 09:21
@github-actions github-actions Bot added this to the 1.53.0 milestone Nov 12, 2026
jbachorik added a commit that referenced this pull request Nov 12, 2026
…antine entry on main gates it while #979 fixes the root cause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant