Repository navigation
Backport the runtime TSAN suppression for NonblockingBoundedQueue to 26.5 - #112899
alexey-milovidov merged 1 commit into
Conversation
…26.5 Every 26.5 pull request keeps failing the TSan integration shards with "Sanitizer assert found for instance zoo3-1", whose Keeper container log carries a ThreadSanitizer data race between the slot payload write in NonblockingBoundedQueue::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. master fixed this in ClickHouse#112695 by registering the two anchored tryPush patterns through __tsan_default_suppressions. That fix is not on 26.5, and it cannot be cherry-picked: base/base/sanitizer_options.h does not exist on this branch, so the hook goes beside the existing __tsan_default_options in programs/main.cpp, inside the same "#ifdef THREAD_SANITIZER" block. The change is purely additive here. ClickHouse#107083, which added the NO_SANITIZE_THREAD attributes that ClickHouse#112695 removed as ineffective, was never backported either, so there is no attribute to delete. A function attribute could not have suppressed these reports anyway: 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 into the annotated one. 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 a "race:" entry also hides heap-use-after-free reports through the frame it names. Sanitizer builds only: outside THREAD_SANITIZER the hook is preprocessed away, and the queue header change is a comment. Co-Authored-By: Claude Fable 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 rounds on identical content;
Severity: ❌ blocker / Beyond the gate, I independently enumerated the invariant carriers before comparing against the Session id: cron:clickhouse-review-slot-50:20260801-111300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-42:20260801-101000 |
|
cc @al13n321 @Michicosun, could you review this? It backports the merged #112695 runtime TSan suppression to 26.5, where it is purely additive because #107083 never landed here, so there is no ineffective |
|
Workflow [BackportPR], commit [3d52363] Summary: ✅ |
…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 #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. #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 (#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 #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]>
Backport of #112695 to 26.6, requested by alexey-milovidov on #112722. 26.6 still carries the defect and has no fix. `Integration tests (amd_tsan, N/6)` fails in teardown with `Sanitizer assert found for instance zoo<N>`, from a TSAN data race report between the `slot.value` write in `NonblockingBoundedQueue::tryPush` and the read in `tryPop`. The report is a false positive. The release/acquire handoff on `slot.pos` orders every access to a slot payload, and there is no non-protocol payload access anywhere in the class, so the code is isomorphic to Vyukov's original implementation. But `abort_on_error=1` in `__tsan_default_options` turns the report into an aborted Keeper node, so healthy runs go red. A `NO_SANITIZE_THREAD` attribute cannot suppress it. Neither `KeeperRequestForSession` nor `KeeperResponseForSession` declares an `operator=`, so the racing access happens in the implicitly generated move assignment, a separate function that keeps `sanitize_thread`. The attribute also prevents that un-attributed callee from being inlined into the attributed caller, which is what creates the frame split that defeats it. A runtime `__tsan_default_suppressions` entry is consulted for every frame of a report, so one entry covers the whole nested move chain. Register that hook with two anchored patterns for the two Keeper instantiations. Only `tryPush` is listed: the `dequeue_pos` compare-exchange gives one consumer sole ownership of a slot before the move-out in `tryPop`, so a pop/pop payload race cannot occur at any consumer count, and each `race:` entry also hides heap-use-after-free reports through the frame it names. Anchoring is load-bearing. Patterns are matched against each frame's function, file and module name, and `clickhouse-keeper-bench` is a symlink to the same binary, so an unqualified pattern would also silence its three unrelated `NonblockingBoundedQueue<QueueItem>` queues. Verified it does not. This is purely additive, unlike the master commit: #107083, which added the attributes master removes, was never backported to 26.6, so there is no attribute to strip here. A straight cherry-pick does not apply (`git apply --check` fails on both files); on 26.6 the hook goes in `base/base/sanitizer_options.h`, which is master's own placement, whereas the 26.5 sibling #112899 had to use `programs/main.cpp` because that header does not exist on 26.5. Non-sanitizer builds are unaffected: the hook is inside `#ifdef THREAD_SANITIZER` and the other change is a comment, so there is no codegen change and no performance impact. A suppression only affects whether TSAN prints or aborts on a report. No test, matching #112695. The only oracle is a CI-side absence property over many runs, which no functional test can assert. Co-Authored-By: Claude Fable 5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Related: #112695
Related: #112722
Description
Every
26.5pull request keeps failing the TSan integration shards withSanitizer assert found for instance zoo3-1. The Keeper container log carries a ThreadSanitizer 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. Most recent instance: 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 by registering the two anchored
tryPushpatterns 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.That fix cannot be cherry-picked here, which is why I authored the backport by hand:
base/base/sanitizer_options.hdoes not exist on this branch, so the hook goes beside the existing__tsan_default_optionsinprograms/main.cpp, inside the same#ifdef THREAD_SANITIZERblock. The change is purely additive: #107083, which added the attributes #112695 removed as ineffective, was never backported either, so there is nothing to delete.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 reports through the frame it names.26.5has exactly two instantiations of the queue, both inKeeperRequestDispatcher, so the two patterns cover it completely.Sanitizer builds only: outside
THREAD_SANITIZERthe hook is preprocessed away, and inside it is oneconst char *return read once at sanitizer init. The queue header change is a comment. There is no new test, matching #112695: the only end-to-end oracle is the TSan integration shards going quiet, which is a CI-side property over many runs.