Skip to content

Widen the Keeper request-size TSan suppression to the whole bytesSize subtree - #115524

Merged
alexey-milovidov merged 1 commit into
masterfrom
keeper-bytessize-tsan-suppression
Aug 20, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
keeper-bytessize-tsan-suppression

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 19, 2026 •

Copy link
Copy Markdown
Member

Related: #113552
Related: #112695

On amd_tsan integration shards the Keeper container occasionally writes a ThreadSanitizer report for the request the dispatch thread just popped, which aborts the container. helpers/cluster.py then raises Sanitizer assert found for instance zooN during cluster.shutdown(), and whichever test happened to run last goes red - the victim is incidental. This time it was test_database_replicated_settings/test.py::test_database_replicated_with_internal_replication[1-1]:

WARNING: ThreadSanitizer: data race (pid=1)
  Read of size 1 ... by thread T32:
    #0 std::__1::basic_string<...>::__is_long() const
    #2 Coordination::GetRequest::bytesSize() const           src/Common/ZooKeeper/IKeeper.h:532
    #4 DB::getRequestBytesCost(...)                          src/Coordination/KeeperRequestDispatcher.cpp:94
    #5 DB::KeeperRequestDispatcher::tryPopRequest(...)       src/Coordination/KeeperRequestDispatcher.cpp:434
  Previous write of size 8 ... by thread T5:
    #3 Coordination::GetRequest::GetRequest()                src/Common/ZooKeeper/IKeeper.h:525
    #18 Coordination::ZooKeeperRequestFactory::get(...)      src/Common/ZooKeeper/ZooKeeperCommon.cpp:1786
    #19 DB::KeeperTCPHandler::receiveRequest()               src/Server/KeeperTCPHandler.cpp:787

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=dddf61ccff5828bb6937cfe680874a04be35932f&name_0=MasterCI&name_1=Integration%20tests%20%28amd_tsan%2C%206%2F6%29

There is no real race. KeeperTCPHandler::receiveRequest writes every payload field of the request - xid, then readImpl, then the tracing context - before publishing it with putRequest; the only post-publication write is on the consumer's own side. getRequestBytesCost reads the vptr and those fields.

#113552 added the entry for this report as race_top:^DB::getRequestBytesCost. race_top: matches the innermost frame only, so it covered the vptr read, which ThreadSanitizer attributes to the call site inside getRequestBytesCost. Suppressing that does not stop the run: the very next racy access is the path read inside Coordination::GetRequest::bytesSize, one frame below, and it aborts the container all the same. That is the report above. So this switches the entry to race:, which matches any frame and therefore covers the whole callee subtree. The subtree is only bytesSize, a read-only size computation, and a use-after-free blinded there still surfaces on the next access to the same request in dispatchThread.

Validation

Against the real ThreadSanitizer runtime, with a harness whose handoff is deliberately unsynchronized so a report is produced on every run and the only variable is which patterns match the frame shape. Arms differ only in the string returned by __tsan_default_suppressions. banner counts runs printing the ================== line, which is exactly what the integration harness greps to raise the assert.

suppression string vptr shape (#113552) bytesSize shape (this report)
(empty) 8/10 10/10
race_top:^DB::getRequestBytesCost 8/10 9/10
race:^DB::getRequestBytesCost 0/20 0/20

In the race_top: / vptr-shape cell the surviving report is exactly the one master hit: race_top: suppresses the vptr read, the run continues, and the path.size() read inside bytesSize is reported instead.

Controls: a typo'd pattern (race:^DB::getRequestBytesCostXX) parses but suppresses nothing (10/10 banner), so the entry's liveness is not assumed; a mangled type token (raceX:) makes the runtime die with failed to parse suppressions, confirming this hook is the live channel; print_suppressions=1 shows the new entry being hit. ci/jobs/scripts/check_style/check_cpp.sh passes. Non-TSan builds are unaffected - the hook is inside #ifdef THREAD_SANITIZER.

Changelog category (leave one):

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

Workflow [PR]
Sync PR [sync-upstream/pr/115524]

…e` subtree

On `amd_tsan` integration shards the Keeper container occasionally writes a
ThreadSanitizer report for the request the dispatch thread just popped, which
aborts the container. `helpers/cluster.py` then raises
`Sanitizer assert found for instance zooN` during `cluster.shutdown()`, and
whichever test happened to run last goes red; the victim is incidental.

There is no real race: `KeeperTCPHandler::receiveRequest` writes every payload
field of the request before publishing it with `putRequest`, and
`getRequestBytesCost` on the consumer side only reads the vptr and those fields.

The existing entry was added as `race_top:^DB::getRequestBytesCost`, which
matches the innermost frame only. That covered the vptr read, attributed to the
call site inside `getRequestBytesCost` - but suppressing it just moved the
report one frame down, to the `path` read inside
`Coordination::GetRequest::bytesSize`, which aborts the container all the same.
Use `race:` so the entry covers the whole callee subtree; that subtree is only
`bytesSize`, a read-only size computation.

Validated against the real ThreadSanitizer runtime with a harness that
reproduces both frame shapes (arms differ only in the string returned by
`__tsan_default_suppressions`; `banner` counts runs printing the
`==================` line the integration harness greps for):

| suppression                                | vptr shape | `bytesSize` shape |
|--------------------------------------------|------------|-------------------|
| (empty)                                    | 8/10       | 10/10             |
| `race_top:^DB::getRequestBytesCost`        | 8/10       | 9/10              |
| `race:^DB::getRequestBytesCost`            | 0/20       | 0/20              |

With `race_top:` the surviving report is exactly the one master hit: the
`path.size()` read inside `bytesSize`, one frame below `getRequestBytesCost`.
Controls: a typo'd pattern parses but suppresses nothing (10/10 banner), a
mangled type token makes the runtime die with `failed to parse suppressions`,
and `print_suppressions=1` shows the new entry being hit.

CI report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=dddf61ccff5828bb6937cfe680874a04be35932f&name_0=MasterCI&name_1=Integration%20tests%20%28amd_tsan%2C%206%2F6%29

Related: #113552
Related: #112695

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c8f8e77]

Summary: ✅


AI Review

Summary

This PR widens the Keeper ThreadSanitizer suppression from race_top:^DB::getRequestBytesCost to race:^DB::getRequestBytesCost so that reports inside bytesSize() are silenced as well as the vptr read at the call site. I found one major issue: the broader suppression can now hide real request-payload lifetime/race bugs on dispatcher paths that discard a request immediately after tryPopRequest, so I would not merge it as-is.

Findings

⚠️ Majors

  • [base/base/sanitizer_options.h:87] race:^DB::getRequestBytesCost now suppresses every request bytesSize() subtree, not just the false-positive vptr read. In the current dispatcher, a popped request can be dropped immediately on the dead-session or soft-memory-limit paths (src/Coordination/KeeperRequestDispatcher.cpp:857-889), so a genuine race/UAF in request-specific payload reads such as Coordination::GetRequest::bytesSize (src/Common/ZooKeeper/IKeeper.h:532) may never be re-exposed outside the suppressed stack. Narrow the suppression to the concrete Coordination::*Request::bytesSize frame(s) from the report, or another shape that does not blanket every call under getRequestBytesCost.
Final Verdict

⚠️ Changes requested: the new suppression is too broad and can hide real bytesSize() lifetime bugs that the previous race_top: entry would still leave visible elsewhere.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 19, 2026
return "race:^NonblockingBoundedQueue<DB::KeeperRequestForSession>::tryPush\n"
"race:^NonblockingBoundedQueue<DB::KeeperResponseForSession>::tryPush\n"
"race_top:^DB::getRequestBytesCost\n";
"race:^DB::getRequestBytesCost\n";

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.

race_top:^DB::getRequestBytesCost only blinded the vptr false positive at the call site. This change to race:^DB::getRequestBytesCost suppresses every report from every request type's bytesSize() subtree instead.

That is wider than the safety argument in the new comment. After the suppressed read in tryPopRequest, the dispatcher can immediately drop the request on the dead-session path (src/Coordination/KeeperRequestDispatcher.cpp:857-866) or the soft-memory rejection path (src/Coordination/KeeperRequestDispatcher.cpp:878-889). Those paths never touch GetRequest::path again, so a real lifetime/race bug in Coordination::*Request::bytesSize would now be fully hidden instead of surfacing on a later unsuppressed access.

Can we keep this narrow by suppressing the concrete Coordination::*Request::bytesSize frame(s) from the report, rather than every stack that passes through DB::getRequestBytesCost?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I strongly dislike the fact that Keeper required TSan suppressions. All the ClickHouse codebase, which is 100x larger, never required that. However, I trust the engineers of Keeper and find this tolerable.

@clickhouse-gh

clickhouse-gh Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing c8f8e775a with master 90e6c433c (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 703.88 MiB 700.84 MiB -3.04 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

7 translation units recompiled, 7 s compile time in total, 7 of them have a recent master baseline.

Job report

@alexey-milovidov alexey-milovidov self-assigned this Aug 20, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 20, 2026
Merged via the queue into master with commit d45e042 Aug 20, 2026
180 checks passed
@alexey-milovidov
alexey-milovidov deleted the keeper-bytessize-tsan-suppression branch August 20, 2026 15:40
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ci 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.

2 participants