Repository navigation
Backport the runtime TSan suppression for NonblockingBoundedQueue to 26.7 - #112916
clickhouse-gh[bot] merged 1 commit into
Conversation
…26.7 The TSan integration shards abort in teardown with `Sanitizer assert found for instance zoo<N>`. The Keeper container log carries a data race between the slot payload write in `NonblockingBoundedQueue<DB::KeeperResponseForSession>::tryPush` and the read in `tryPop`. The release/acquire handoff on `slot.pos` orders every access to a slot payload, so the report is a false positive, but it aborts the Keeper process and reds the whole shard. master fixed this in ClickHouse#112695 by registering two anchored `tryPush` patterns through `__tsan_default_suppressions`. A function attribute cannot suppress these reports: the reported access happens in the element type's implicitly generated move assignment, a separate function that stays instrumented, and the attribute additionally prevents it from being inlined. A runtime suppression is consulted for every frame of a report, so one entry per instantiation covers the whole nested move chain. Authored by hand rather than cherry-picked: master's queue-header hunk does not apply here, because its context is the `NO_SANITIZE_THREAD` attribute this branch never had. ClickHouse#107083, which added those attributes, was never backported either, so this change is purely additive and there is nothing to remove. The hook goes in `base/base/sanitizer_options.h` beside the existing `__tsan_default_options`, which is master's placement; the 26.5 sibling (ClickHouse#112899) had to use `programs/main.cpp` because that header does not exist there. Only `tryPush` is listed. `tryPop` writes the payload too, but the `dequeue_pos` compare-exchange gives one consumer sole ownership of a slot before the move-out, so two pops never touch one payload concurrently, whatever the consumer count. A `tryPop` entry would be dead, and each `race:` entry also hides heap-use-after-free reports through the frame it names, so the set is kept at the proven minimum of two. Both patterns are `^`-anchored on the two Keeper instantiations and each names exactly one live symbol in the built binary. keeper-bench also instantiates the queue, but its element type is a private nested struct of `StorageRunner`, so it demangles as `NonblockingBoundedQueue<StorageRunner::QueueItem>` and matches neither pattern. The signature has not been observed on this branch, unlike 26.5 and 26.6, but that is sample size rather than immunity: at master's observed rate the probability of seeing zero occurrences is about 88 percent on this branch's TSan integration build volume, and about 72 percent on each of 26.5 and 26.6, which did see one. The reason to include 26.7 is structural. Both carrier files are present with both explicit instantiations, and its copy of the queue header is md5-identical to 26.6's. 26.4 and older lack the files entirely. Sanitizer builds only: outside `THREAD_SANITIZER` the hook is preprocessed away, verified as zero hook symbols and zero payload strings in a non-sanitizer build, and inside it is one `const char *` returning a fixed string read once at sanitizer init. The queue header change is a comment, so no executable line of the queue changed. No new test, matching ClickHouse#112695: the only end-to-end oracle is the TSan integration shards going quiet over many runs. Co-Authored-By: Claude Fable 5 <[email protected]>
Internal second-model review (click to expand)Two independent passes over this change: my own cold review of the resulting code Gate review: 0 findings. Its stated coverage: both touched files read in full, all queue My own review: 3 findings, 1 accepted and fixed, 2 rejected with evidence.
💡 A successfully suppressed race still makes the runtime print 💡 For completeness, what I checked and found correct rather than reporting: the carrier set Session id: cron:clickhouse-review-slot-48:20260801-140200 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-41:20260801-130600 |
|
cc @thevar1able @antonio2368, could you review this? It is the 26.7 backport of the already-merged #112695: a |
|
Workflow [BackportPR], commit [4e23789] Summary: ✅ |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Related: #112695
Related: #112722
Description
The TSan integration shards abort in teardown with
Sanitizer assert found for instance zoo<N>. The Keeper container log carries a data race between the slot payload write inNonblockingBoundedQueue<DB::KeeperResponseForSession>::tryPushand the read intryPop. The release/acquire handoff onslot.posorders every access to a slot payload, so the report is a false positive. Example on a 26.5 backport branch: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112722&sha=21ba2dbcf7a5d9e1a4f1e1357677f5429f121040&name_0=BackportPR&name_1=Integration%20tests%20%28amd_tsan%2C%203%2F6%29master fixed this in #112695 with two anchored
tryPushpatterns in__tsan_default_suppressions. A function attribute cannot suppress the reports: the access happens in the element type's implicitly generated move assignment, a separate function that stays instrumented, which the attribute also keeps from being inlined. A runtime suppression is consulted for every frame.I authored this by hand because the cherry-pick does not apply and the label route is unavailable: #112695 carries no
*-must-backportlabel and I cannot apply one. @alexey-milovidov asked for it in #112722; 26.5 is #112899.The hook goes beside the existing
__tsan_default_optionsinbase/base/sanitizer_options.h, master's placement (26.5 lacks that header, so #112899 usedprograms/main.cpp). Purely additive: #107083, whose attributes #112695 removed as ineffective, was never backported here.Only
tryPushis listed.tryPopwrites the payload too, but thedequeue_poscompare-exchange gives one consumer sole ownership of a slot before the move-out, so two pops never touch one payload concurrently, whatever the consumer count. AtryPopentry would be dead, and arace:entry also hides heap-use-after-free through that frame.Sanitizer builds only, no performance impact: outside
THREAD_SANITIZERthe hook is preprocessed away, and inside it returns a fixed string read once at sanitizer init. The queue header change is a comment. No new test, matching #112695: the only end-to-end oracle is the TSan shards going quiet over many runs. The comment saysTSanrather than master'sTSAN, per.claude/CLAUDE.md; happy to unify across the three branches.Why 26.7 is affected although the signature has not been observed on it
Over the last 45 days the signature appears four times on master, plus once on a robot backport branch targeting 26.6 and once on one targeting 26.5. It never appears with
26.5,26.6or26.7as the head ref, so the zero on 26.7 is not distinctive. Worth flagging for anyone re-running this: two of the master occurrences escape the obvious query, because the TSan banner overwrites the instance name and the harness line readsSanitizer assert found for instance ==================rather than naming azoocontainer.That zero is sample size, not immunity. At master's observed rate the probability of seeing zero occurrences is about 84 percent on 26.7's TSan integration build volume, and about 64 percent on each of 26.5's and 26.6's. So no release branch can be shown immune from this data, and I am not claiming the data shows 26.7 susceptible either.
The case for 26.7 is structural. Both carrier files are present,
src/Common/NonblockingBoundedQueue.handsrc/Coordination/KeeperRequestDispatcher.cpp, with both explicit instantiations. Its copy of the queue header is md5-identical to 26.6's, which did see the failure. 26.4 and older lack the files entirely and are immune for that reason.One detail on scope:
keeper-benchalso instantiates the queue, but its element type is a private nested struct ofStorageRunner, so it demangles asNonblockingBoundedQueue<StorageRunner::QueueItem>and matches neither anchored pattern. Verified in the built binary, where each pattern names exactly one live symbol and that one names none.