Repository navigation
Suppress the Keeper request-size vptr TSAN report at its top frame - #113552
Conversation
On amd_tsan integration shards the Keeper container occasionally writes
WARNING: ThreadSanitizer: data race on vptr (ctor/dtor vs virtual call)
Read by the dispatch thread: getRequestBytesCost KeeperRequestDispatcher.cpp:92
tryPopRequest KeeperRequestDispatcher.cpp:428
Previous write by a KeeperTCPHandler thread: the request's constructor, via
ZooKeeperRequestFactory::get / receiveRequest
which aborts the container, so helpers/cluster.py raises "Sanitizer assert found
for instance zooN" during cluster.shutdown() and whichever test ran last in the
module goes red. Observed on two unrelated PRs; the victim test is incidental.
There is no real race. receiveRequest constructs and fills the request, then
publishes it with tryPush, which stores slot.pos with memory_order_release after
writing slot.value; the dispatch thread loads slot.pos with memory_order_acquire
before moving out. The constructor's vptr store precedes that release store in
program order, so it is ordered before the read. The request is written after
publication -- to its tracing spans three lines below the suppressed read, and
to xid and tracing_context -- but not to anything the read touches: the vptr is
written only by the constructor, and the payload fields bytesSize reads (path,
data, acls, scheme, include_ttl, the SetWatches path lists, MultiRequest's
subrequests, Reconfig's member lists) have no server-side assignment after
publication. The xid write is the instructive case: all 27 of its appearances in
a bytesSize override sit inside sizeof(xid), so no override reads its value. The
"ctor/dtor vs virtual call" wording is derived from the access tags alone --
__tsan_vptr_update marks every vptr store kAccessVptr and the report type
follows from that tag -- not from a detected concurrent constructor. Why TSAN
loses the happens-before edge is left unresolved, as it was for the neighbouring
payload race.
The two existing entries cannot match this report: they anchor on
NonblockingBoundedQueue<...>::tryPush, and those strings appear nowhere in it.
That race was reported inside the queue; this one is a vptr read on the pointee,
one frame above the queue, with the queue on neither stack.
race_top is matched against the innermost frame only, so the unavoidable
use-after-free blinding stays inside getRequestBytesCost, whose whole body is
bytesSize() plus sizeof, while still covering all four of its call sites -- the
producer at :417, the observed one at :428, and both in dispatchThread. An
any-frame race: entry on the same function, or an entry on tryPopRequest, would
also silence the report but would hide a use-after-free anywhere beneath the pop
gateway, including the span finalization that mutates the request. The request's
other virtual calls are deliberately left uncovered and the comment says so.
Validated against the real ThreadSanitizer runtime with a standalone harness that
drives __tsan_vptr_update / __tsan_vptr_read, so it takes the production report
path without any undefined behaviour of its own. Arms differ only in the string
returned by __tsan_default_suppressions(), 20 runs each: empty gives the banner in
20/20 runs and 0/20 clean; this entry gives 0/20 and 20/20; an entry naming
getResponseBytesCost gives 20/20, as do the two pre-existing entries alone. A
mangled type token makes the runtime die with "failed to parse suppressions",
confirming the hook is the live channel, and a typo'd pattern parses while
suppressing nothing. Since the function is static and fully inlined it has no ELF
symbol, so liveness was checked in the built binary's debug info: one matching
linkage name, four inlined instances at lines 417/428/903/948, and symbolizing a
real PC from the :428 range reproduces the report's exact frame pair.
TSAN builds only; the hook is inside #ifdef THREAD_SANITIZER.
Internal second-model review (click to expand)This diff went through two review rounds before publication: a cold read of the resulting code and a
Also checked and clean: patterns are tested against a frame's function, file and module name, but the Session id: cron:clickhouse-review-slot-51:20260805-182300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-review-slot-51:20260805-182300 |
|
cc @alexey-milovidov @antonio2368, could you review this? It adds one |
|
Workflow [PR], commit [df7d4ca] Summary: ✅
AI ReviewSummaryThis PR adds a ThreadSanitizer Final Verdict
|
CI finish ledger — fb21b1dEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
None is PR-caused. This PR's entire diff is one file, Fix-presence probe for the Gates: (a) 175 check-runs, 0 queued/in_progress/pending/waiting; (b) Session id: cron:our-pr-ci-monitor:20260806-050000 Edited to correct the commit hash in the heading: I had truncated it to the first 12 characters and completed the rest incorrectly. The hash now shown is this PR's actual head. Nothing else changed; every finding above was measured against that head. |
|
Fixing PR for the It replaces the oracle that counted every The failure on this PR was on a build that predates that merge. Probing the test file per build (marker No action needed here beyond a rerun or a rebase onto current master. |
|
A third carrier of the suppressed report, and a measurement that may be worth adding to this PR's case.
Read side Two things I measured while triaging that failure: The same test module also produced the payload race the merged 112695 covers, in two other runs: The abort has a downstream cost beyond reddening the victim test. In one run the aborted Keeper container restarted, which expired a server's ZooKeeper session mid-test; the So a report suppressed here does not only cost one red test line; it can also surface as an unrelated-looking For the record on the failure I came from: |
…eeper-request-size-vptr-tsan-report
CI finish ledger - 2fc9c7cCI is fully finished on this head: 148 success, 25 skipped, 2 failure. The praktika report shows 0 dropped jobs. This PR touches only
The merged #112849 ("Do not apply parallel replicas to the child plans of a Session id: cron:our-pr-ci-monitor:20260811-170000 |
…eeper-request-size-vptr-tsan-report
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units6 translation units recompiled, 5 s compile time in total, 6 of them have a recent master baseline. |
CI finish ledger for fb8f8d3CI is fully finished on this head (176 leaves, 0 dropped jobs). Every failure below has an owner.
Confirmed frame-by-frame from the server error log rather than by STID prefix: Not PR-caused: the entire diff is Session id: cron:our-pr-ci-monitor:20260812-163000 |
CI finish ledger - 8b8702fEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The diff at this head is Session id: cron:our-pr-ci-monitor:20260814-083000 |
CI finish ledger for bf0634aCI is fully finished on this head and there are no failures to attribute: 152 checks
|
CI finish ledger for df7d4caCI is fully finished on this head and there are no failures to attribute: 151 checks succeeded, 26 skipped, 0 failed. The praktika report for this head is
Session id: cron:our-pr-ci-monitor:20260815-180000 |
…e` subtree On `amd_tsan` integration shards the Keeper container occasionally writes a ThreadSanitizer report for the request the dispatch thread just popped, which aborts the container. `helpers/cluster.py` then raises `Sanitizer assert found for instance zooN` during `cluster.shutdown()`, and whichever test happened to run last goes red; the victim is incidental. There is no real race: `KeeperTCPHandler::receiveRequest` writes every payload field of the request before publishing it with `putRequest`, and `getRequestBytesCost` on the consumer side only reads the vptr and those fields. The existing entry was added as `race_top:^DB::getRequestBytesCost`, which matches the innermost frame only. That covered the vptr read, attributed to the call site inside `getRequestBytesCost` - but suppressing it just moved the report one frame down, to the `path` read inside `Coordination::GetRequest::bytesSize`, which aborts the container all the same. Use `race:` so the entry covers the whole callee subtree; that subtree is only `bytesSize`, a read-only size computation. Validated against the real ThreadSanitizer runtime with a harness that reproduces both frame shapes (arms differ only in the string returned by `__tsan_default_suppressions`; `banner` counts runs printing the `==================` line the integration harness greps for): | suppression | vptr shape | `bytesSize` shape | |--------------------------------------------|------------|-------------------| | (empty) | 8/10 | 10/10 | | `race_top:^DB::getRequestBytesCost` | 8/10 | 9/10 | | `race:^DB::getRequestBytesCost` | 0/20 | 0/20 | With `race_top:` the surviving report is exactly the one master hit: the `path.size()` read inside `bytesSize`, one frame below `getRequestBytesCost`. Controls: a typo'd pattern parses but suppresses nothing (10/10 banner), a mangled type token makes the runtime die with `failed to parse suppressions`, and `print_suppressions=1` shows the new entry being hit. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=dddf61ccff5828bb6937cfe680874a04be35932f&name_0=MasterCI&name_1=Integration%20tests%20%28amd_tsan%2C%206%2F6%29 Related: ClickHouse#113552 Related: ClickHouse#112695 Co-Authored-By: Claude Fable 5 <[email protected]>
|
@alexey-milovidov, could you apply |
Related: #112695
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Suppress a false-positive ThreadSanitizer
vptrreport on the Keeper request queue's consumer side, which aborted the Keeper container and reddened unrelated integration tests.Description
On
amd_tsanintegration shards the Keeper container sometimes writesThat aborts the container, so
helpers/cluster.pyraisesSanitizer assert found for instance zooNduringcluster.shutdown()and whichever test ran last goes red. Seen on two unrelated PRs;the victim is incidental.
There is no real race.
receiveRequestconstructs and fills the request, then publishes itwith
tryPush, which storesslot.poswithmemory_order_releaseafter writingslot.value; thedispatch thread loads it with
memory_order_acquirebefore moving out. The constructor's vptr storeprecedes that release store in program order, so it is ordered before the read. The request is
written after publication, but only to the tracing
spansmember and toxid, whilebytesSize()reads the vptr, written only by the constructor, and
path, which no server-side code assigns. The"ctor/dtor vs virtual call" wording follows from the access tags alone (
__tsan_vptr_updatemarksany vptr store
kAccessVptr), not from a detected concurrent constructor.#112695 is already present on the failing builds and cannot match: its two entries anchor on
NonblockingBoundedQueue<...>::tryPush, strings absent from this report. That race was reportedinside the queue; this one is a vptr read on the pointee, one frame above it.
So this adds one entry to the same hook.
race_topmatches the innermost frame only, which keepsthe unavoidable use-after-free blinding inside
getRequestBytesCost, whose whole body isbytesSize()plussizeof, while still covering all four of its call sites. The object's othervirtual calls are deliberately not listed; the comment says so.
Validated against the real ThreadSanitizer runtime: 20/20 runs abort without the entry, 20/20 clean
with it, with control arms.
Validation
Arms differ only in the string returned by
__tsan_default_suppressions(), 20 runs each,production
TSAN_OPTIONS.BANNERcounts runs printing the==================line, which isexactly what the integration harness greps to raise the assert.
race_top:^DB::getRequestBytesCostrace_top:^DB::getResponseBytesCostA mangled type token (
raceX_top:) makes the runtime die withfailed to parse suppressions,confirming this hook is the live channel; a typo'd pattern parses but suppresses nothing, so the
entry's liveness was checked in the built binary.
getRequestBytesCostisstaticand inlined,so it has no ELF symbol: symbolizing a real PC from the inlined
:428range reproduces thereport's exact frame pair, and all four call sites report it as the top frame.
ci/jobs/scripts/check_style/check_cpp.shpasses. Non-TSAN builds are unaffected: the hook isinside
#ifdef THREAD_SANITIZER.Version info
26.8.1.1476(included in26.8and later)