Repository navigation
Suppress TSAN error in NonblockingBoundedQueue - #107083
Conversation
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]>
|
Workflow [PR], commit [8ce4be6] Summary: ✅
AI ReviewSummaryThis PR tries to suppress intermittent ThreadSanitizer reports on Missing context / blind spots
Findings
|
| /// 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) |
There was a problem hiding this comment.
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.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 4/4 (100.00%) · Uncovered code |
|
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. |
|
📊 Cloud Performance Report ✅ AI verdict: 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
|
alexey-milovidov
left a comment
There was a problem hiding this comment.
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).
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]>
`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`).
…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]>
…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]>
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]>
Suppress TSAN error in NonblockingBoundedQueue
Changelog category (leave one):
See #106801 for context.
Version info
26.8.1.163(included in26.8and later)