Skip to content

Backport the runtime TSAN suppression for NonblockingBoundedQueue to 26.5 - #112899

Merged
alexey-milovidov merged 1 commit into
ClickHouse:26.5from
groeneai:backport-112695-tsan-suppression-26.5
Aug 1, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:26.5from
groeneai:backport-112695-tsan-suppression-26.5

Conversation

@groeneai

@groeneai groeneai commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Related: #112695
Related: #112722

Description

Every 26.5 pull request keeps failing the TSan integration shards with Sanitizer assert found for instance zoo3-1. The Keeper container log carries a ThreadSanitizer 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. 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%29

master fixed this in #112695 by registering the 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.

That fix cannot be cherry-picked here, which is why I authored the backport by hand: 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: #107083, which added the attributes #112695 removed as ineffective, was never backported either, so there is nothing to delete.

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. 26.5 has exactly two instantiations of the queue, both in KeeperRequestDispatcher, so the two patterns cover it completely.

Sanitizer builds only: outside THREAD_SANITIZER the hook is preprocessed away, and inside it is one const 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.

…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]>
@groeneai

groeneai commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 2 rounds on identical content;
1 finding), plus my own cold review of the resulting code (3 nits). No blockers, no majors.

# Sev Finding Verdict Evidence / action
1 💡 Comment spells TSAN, repo convention is TSan (src/Common/NonblockingBoundedQueue.h:83) AGREE, not applied Correct: .claude/CLAUDE.md:151 says "say ASan, not ASAN, and similar". Left as-is only for backport fidelity: this line is byte-identical to the text merged on master 12 hours earlier (origin/master:src/Common/NonblockingBoundedQueue.h line 84, and #112695's own merged title). Not style-check enforced (check_cpp.sh exits 0). Say the word and I will change it here, or on master and here together.
2 💡 Both comments say a NO_SANITIZE_THREAD attribute "does not work", but 26.5 never had one AGREE, kept deliberately #107083 was never backported, so git grep -ciE no_sanitize origin/26.5 -- src/Common/NonblockingBoundedQueue.h finds nothing. Wording kept because it explains why the runtime hook is the mechanism and pre-empts someone re-adding the attribute; the commit message and PR body both state that there is no attribute to delete on this branch.
3 💡 Comment drops master's clause about "the unrelated asynchronous logging queue" DROPPED, intentional That clause is factually wrong today: git grep -c NonblockingBoundedQueue -- src/Loggers/ is 0 on 26.5, 26.6, 26.7 and master. The backport keeps only the true half.
4 💡 Naming/backtick conventions (f not f(), literals backticked) DROPPED, audit record .claude/CLAUDE.md lines 5 and 9 both satisfied; no bare f() in any added comment line.

Severity: ❌ blocker / ⚠️ major / 💡 nit. Findings are verified against the source
rather than accepted as prose; the cited authority for finding 1 was read directly before agreeing.

Beyond the gate, I independently enumerated the invariant carriers before comparing against the
plan: 26.5 has exactly two instantiations of the queue (KeeperRequestForSession,
KeeperResponseForSession, explicitly instantiated at KeeperRequestDispatcher.cpp:15-16), both
covered by the two patterns, and no keeper-bench queue user as on 26.6/26.7. I also verified
the one way this change could be a silent no-op: BUILD_STANDALONE_KEEPER is OFF and the TSan
build does not set it, so clickhouse-keeper is a symlink to the main.cpp binary and
cluster.py:1332-1338 therefore runs clickhouse keeper, which does carry the hook.
cluster.py:595 sets no suppressions=, so nothing overrides it.

Session id: cron:clickhouse-review-slot-50:20260801-111300

@groeneai

groeneai commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, for what this change controls. The TSan report itself is a rare false positive under integration load and is deliberately not reproduced locally (the mechanism was established at IR level on #112695). The property this change asserts is deterministic: build 26.5 with -DSANITIZE=thread, then nm -C build-tsan/programs/clickhouse | grep __tsan_default_suppressions. Without the change the only symbol is the runtime's own weak default (W); with it there is exactly one strong definition (T), and strings -a carries both patterns.
b Root cause explained? Yes. tryPush publishes a slot payload with slot.pos.store(release) and tryPop guards with load(acquire), so the reported pair is not a real race. TSan attributes the access to the element type's implicitly generated move assignment, a separate function that stays instrumented, so a NO_SANITIZE_THREAD attribute on tryPush cannot suppress it, and the attribute additionally prevents that function from being inlined into the annotated one. Report-level matching via __tsan_default_suppressions is immune to the frame split.
c Fix matches root cause? Yes. It is the same remedy #112695 landed on master, at the same layer (report-level suppression keyed on the two frames that actually appear), adapted to this branch's hook location. No test was widened, no tag added, no data reduced.
d Test intent preserved / new tests added? Preserved; no new test, matching #112695, which shipped none. The only end-to-end oracle is the TSan integration shards going quiet, a CI-side property over many runs. Coverage of the suppression itself is asserted mechanically instead (items a and e). The patterns are anchored on the two Keeper instantiations, so instrumentation elsewhere is untouched.
e Both directions demonstrated? Yes, on Build-ID-verified binaries. Pre-change TSAN build f2685b834291f73d5c4f9ffb492f1cb60cc292c8: 0 suppression strings, __tsan_default_suppressions present only as the runtime's weak W default. Post-change 375591d8f8eaa73242ec9a4dec43b75352082dbf: exactly one T definition, both patterns present and byte-identical to master's payload (md5 c79171ab590d082e13437bd2f5718927). Positive control proving the runtime actually consumes the hook rather than ignoring it: mangling the suppression category to bogusrace (build c5260d3078885fc364653a25e34a74ae79c8eac4) makes startup fail with ThreadSanitizer: failed to parse suppressions and exit 134; reverting restores Build ID 375591d8 exactly.
f Fix is general across code paths? Yes. Both queue instantiations on this branch are covered (KeeperRequestForSession, KeeperResponseForSession, explicitly instantiated at src/Coordination/KeeperRequestDispatcher.cpp:15-16), and each pattern matches exactly one live symbol, so neither entry is dead. tryPop is deliberately excluded: the dequeue_pos compare-exchange gives one consumer sole ownership of a slot before the move-out, so a tryPop entry would be dead and would also hide heap-use-after-free through that frame. On 26.5 the queue has no non-Keeper user, so nothing else is affected. Reachability confirmed for the failing zoo* process: BUILD_STANDALONE_KEEPER defaults OFF (CMakeLists.txt:206) and the TSAN build configs do not set it, so clickhouse-keeper is a symlink to the binary built from programs/main.cpp.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A. There is no data path, no argument and no type parameter in this change; the hook returns a fixed string consulted once at sanitizer init. The type-level analogue, queue element types, is covered under (f): both instantiations are named explicitly.
h Backward compatible? Yes, trivially. No setting, no serialization format, no protocol and no on-disk change, so no SettingsChangesHistory.cpp entry applies. Purely additive on this branch: #107083 was never backported, so there is no attribute to remove.
i Invariants and contracts preserved? Yes. The __tsan_default_suppressions contract is that it is defined with external C linkage exactly once per binary; verified as exactly one strong definition, and it is the only definition in the tree outside vendored compiler-rt. The queue's own ordering invariant is untouched, since the header change is a comment. Placement inside the existing #ifdef THREAD_SANITIZER block keeps non-TSAN builds unaffected, confirmed empirically: the Debug build of the same tree compiles clean and its binary contains neither the symbol nor the strings. Style check ci/jobs/scripts/check_style/check_cpp.sh returns 0.

Session id: cron:clickhouse-impl-slot-42:20260801-101000

@groeneai

groeneai commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author

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 NO_SANITIZE_THREAD attribute to remove; the hook goes beside the existing __tsan_default_options in programs/main.cpp because base/base/sanitizer_options.h does not exist on this branch.

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Aug 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [3d52363]

Summary: ✅

@alexey-milovidov alexey-milovidov self-assigned this Aug 1, 2026
@alexey-milovidov
alexey-milovidov merged commit 0fb387e into ClickHouse:26.5 Aug 1, 2026
34 checks passed
clickhouse-gh Bot pushed a commit that referenced this pull request Aug 1, 2026
…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]>
PedroTadim pushed a commit that referenced this pull request Sep 4, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants