Skip to content

Suppress TSAN error in NonblockingBoundedQueue - #107083

Merged
alexey-milovidov merged 6 commits into
masterfrom
tsanope-suppress
Jul 26, 2026
Merged

alexey-milovidov merged 6 commits into
masterfrom
tsanope-suppress

Conversation

@al13n321

@al13n321 al13n321 commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

See #106801 for context.

Version info

  • Merged into: 26.8.1.163 (included in 26.8 and later)

TSAN very rarely reports a data race between the `slot.value` write in
`tryPush` and the `slot.value` read in `tryPop`, even though the
acquire/release operations on `slot.pos` make such a race impossible
(the code is isomorphic to Vyukov's original implementation). This looks
like a TSAN false positive, so exclude `tryPush` and `tryPop` from
instrumentation of plain memory accesses with `NO_SANITIZE_THREAD`.

Note that TSAN still instruments atomic operations in functions with
this attribute, so the happens-before edges through `slot.pos` remain
visible to it, and accesses to the contents of `T` in callers are still
checked correctly.

Co-Authored-By: Claude Fable 5 <[email protected]>
@al13n321
al13n321 requested a review from antonio2368 June 10, 2026 21:28
@clickhouse-gh

clickhouse-gh Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8ce4be6]

Summary: ✅


AI Review

Summary

This PR tries to suppress intermittent ThreadSanitizer reports on NonblockingBoundedQueue by marking tryPush and tryPop with NO_SANITIZE_THREAD. I do not think it is ready to merge: the suppression is applied to a reusable header-only template, so it disables TSan plain-access checking for the whole queued-value move path, not just the disputed slot.value handoff.

Missing context / blind spots
  • ⚠️ The PR still does not include a minimal reproducer or proof that the reported queue race is a TSan false positive rather than a latent queue or caller bug. That evidence would be needed to justify dropping sanitizer coverage instead of using a narrower suppression.
Findings
⚠️ Majors
  • [src/Common/NonblockingBoundedQueue.h:84-124] The PR promises to suppress one suspected false positive on the queue slot handoff, but NO_SANITIZE_THREAD on the header-only tryPush / tryPop template methods turns off TSan plain-access instrumentation for the whole instantiated body. That includes whatever T move-assignment code gets inlined at slot.value = std::move(value) / out_value = std::move(slot.value), so every current and future NonblockingBoundedQueue<T> instantiation loses race checking in its move path, not just the slot.value producer/consumer transfer. Suggested fix: narrow the suppression to the specific Keeper instantiations or a TSan ignorelist entry, or otherwise make the lost coverage explicit and local to the known false-positive site instead of annotating the common template.
Final Verdict

Needs changes. The current suppression is broader than the PR contract and can hide real ThreadSanitizer reports in queued-type move code.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jun 10, 2026
Comment thread src/Common/NonblockingBoundedQueue.h Outdated
/// atomic operations in such functions, so the happens-before edges through `slot.pos`
/// remain visible to it, and accesses to the contents of `T` in callers are still checked
/// correctly.
NO_SANITIZE_THREAD bool tryPush(T && value)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NO_SANITIZE_THREAD is broader than the reported slot.value handoff. Because NonblockingBoundedQueue is a template and these methods are defined in the header, the attribute covers the whole instantiated body, including any inlined T move assignment at the slot.value = std::move(value) / out_value = std::move(slot.value) transfers. That means a TSan build stops checking plain loads/stores performed by a future queued type's move code whenever it goes through this queue, not just the known producer/consumer slot false positive.

Please either keep the suppression narrower, or make the lost coverage explicit and restrict it to the intended instantiations/TSan ignorelist entry. As written, this common template can hide a real race introduced by a later T while the comment says caller-visible T accesses are still checked.

@antonio2368 antonio2368 self-assigned this Jun 11, 2026
@al13n321
al13n321 enabled auto-merge June 12, 2026 22:45
@clickhouse-gh

clickhouse-gh Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.60% 85.60% +0.00%
Functions 92.70% 92.70% +0.00%
Branches 77.80% 77.80% +0.00%

Changed lines: Changed C/C++ lines covered: 4/4 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh

clickhouse-gh Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Dear @antonio2368, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@clickhouse-gh clickhouse-gh Bot assigned antonio2368 and unassigned antonio2368 Jul 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 37 queries analysed

This sync PR only adds a NO_SANITIZE_THREAD attribute (plus an explanatory comment) to tryPush/tryPop in a lock-free bounded queue to silence a rare TSAN false positive; in release builds that attribute is a no-op and cannot affect query execution. The two ClickBench improvements the gates flagged (Q4 -16.5%, Q15 -18.4%) both land inside master's current variance band, so the deterministic no_change verdicts are correct — these are run-to-run variance, not a real PR effect. No queries warrant action beyond noting the deltas as noise.

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 2ea50af1-1ac4-4ae6-bae8-99cc1a8f02b0
  • MIRAI run: eba0bede-357c-4644-ae64-b94af15fdf79
  • PR check IDs:
    • clickbench_506268_1784014278
    • clickbench_506274_1784014278
    • clickbench_506279_1784014278
    • tpch_adapted_1_official_506287_1784014278
    • tpch_adapted_1_official_506296_1784014278
    • tpch_adapted_1_official_506304_1784014278

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we report this to Google as a bug in TSan?
The reason I'm worried is that TSan only rarely has bugs (we found and reported just a few over the history).

@alexey-milovidov alexey-milovidov self-assigned this Jul 26, 2026
pull Bot pushed a commit to admariner/ClickHouse that referenced this pull request Jul 26, 2026
A Keeper sanitizer report (e.g. a TSan data race in clickhouse-keeper) is
written to raw process stderr (fd 2). clickhouse-keeper, a BaseDaemon, only
redirects fd 2 to a file when logger.stderr is set; the integration keeper
configs set only <log>/<errorlog>, so the report reaches only the container
stderr stream. The zoo* containers are not in ClickHouseCluster.instances, so
the per-instance stderr.log scan in shutdown() never covers Keeper, and
detection falls back to the 'docker compose logs --follow' capture, which is
torn down at shutdown and is not archived into logs.tar.gz. That is why the
Keeper sanitizer report could not be found in the collected logs on ClickHouse#110917.

- docker_compose_keeper.yml: redirect Keeper stderr/stdout to
  /var/log/clickhouse-keeper/ (already bind-mounted and archived) via
  '-- --logger.stderr=... --logger.stdout=...', mirroring server nodes.
- helpers/cluster.py shutdown(): also scan each Keeper instance's stderr.log
  for the sanitizer sign, so the report is detected deterministically once
  Keeper fd 2 no longer reaches the docker.log capture.

The TSan race itself is unrelated to this change and is tracked in ClickHouse#107083.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@alexey-milovidov
alexey-milovidov merged commit 3401bc9 into master Jul 26, 2026
174 of 175 checks passed
@alexey-milovidov
alexey-milovidov deleted the tsanope-suppress branch July 26, 2026 16:18
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 26, 2026
grantholly-clickhouse pushed a commit to grantholly-clickhouse/ClickHouse that referenced this pull request Jul 31, 2026
`Integration tests (amd_tsan, N/6)` fails in teardown with `Sanitizer assert
found for instance zoo<N>`, from a TSAN data race between the `slot.value`
write in `NonblockingBoundedQueue::tryPush` and the read in `tryPop`.

PR ClickHouse#107083 added `NO_SANITIZE_THREAD` to both methods to silence it. That fix
is merged and an ancestor of the failing branch, and the race still fires: 29
CIDB rows over 45 days across 27 distinct pull requests, 3 of them on master,
and 4 after the merge timestamp.

The correctness analysis in ClickHouse#107083 is right. 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 report is a false positive. Only
the chosen mechanism is ineffective:

  * `NO_SANITIZE_THREAD` suppresses instrumentation of plain accesses in the
    annotated function's own body only. 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 causes the frame split that defeats it, because an
    un-attributed callee can never be inlined into an attributed caller.

Measured at IR level on the real header: with the attribute, `tryPush` and
`tryPop` carry 0 plain-access hooks but each still calls the element move out
of line, and that move body carries 10 hooks including the `__tsan_memcpy`
that the CI report names.

Register a `__tsan_default_suppressions` hook instead, with two anchored
patterns for the two Keeper instantiations, and remove the two attributes.
Suppressions are consulted for every frame of a report, so one entry covers
the whole nested move chain, which is what no compile-time mechanism achieves.
Removing the attributes additionally restores plain-access instrumentation in
the queue for all four element types, including the logging and keeper-bench
queues that were being silenced for no reason, while atomics stay instrumented
so the happens-before edges remain visible to TSAN.

Only `tryPush` is listed. A concurrent pop cannot race on a payload, because
`dequeue_pos` gives exactly one consumer ownership of a slot before the
move-out; this was measured, not assumed. 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.

The TSAN-internal path that produces the bogus shadow is not identified.
Shadow-cell eviction is refuted, since it is reached only after the scan finds
no race and can therefore only cause false negatives. The signature is worth
reporting upstream, and the suppression is scoped narrowly enough to drop if
that lands.

Non-sanitizer builds are unaffected: the hook is inside `#ifdef
THREAD_SANITIZER`, and removing the attributes is codegen-neutral without a
sanitizer (same translation unit compiled with and without the attribute
yields byte-identical objects when built without `-g`, and byte-identical
`.text` with `-g`).
alexey-milovidov pushed a commit that referenced this pull request Aug 1, 2026
…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 #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. #107083, which added the NO_SANITIZE_THREAD
attributes that #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]>
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]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
A Keeper sanitizer report (e.g. a TSan data race in clickhouse-keeper) is
written to raw process stderr (fd 2). clickhouse-keeper, a BaseDaemon, only
redirects fd 2 to a file when logger.stderr is set; the integration keeper
configs set only <log>/<errorlog>, so the report reaches only the container
stderr stream. The zoo* containers are not in ClickHouseCluster.instances, so
the per-instance stderr.log scan in shutdown() never covers Keeper, and
detection falls back to the 'docker compose logs --follow' capture, which is
torn down at shutdown and is not archived into logs.tar.gz. That is why the
Keeper sanitizer report could not be found in the collected logs on ClickHouse#110917.

- docker_compose_keeper.yml: redirect Keeper stderr/stdout to
  /var/log/clickhouse-keeper/ (already bind-mounted and archived) via
  '-- --logger.stderr=... --logger.stdout=...', mirroring server nodes.
- helpers/cluster.py shutdown(): also scan each Keeper instance's stderr.log
  for the sanitizer sign, so the report is detected deterministically once
  Keeper fd 2 no longer reaches the docker.log capture.

The TSan race itself is unrelated to this change and is tracked in ClickHouse#107083.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Suppress TSAN error in NonblockingBoundedQueue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants