Repository navigation
Fix data race in ClientBase::onProgress called by LocalConnection from pipeline threads - #128019
Conversation
… from pipeline threads The interactive cancel callback that `LocalConnection::sendQuery` installs (since ClickHouse#100230) also forwards accumulated progress to the client. Nested executors poll it (scalar subqueries, sets), and they run on pipeline threads when a query is analysed inside a running pipeline, for example the query of a materialized view with a scalar subquery over the view source, analysed for every inserted block. The client thread meanwhile calls the same progress handler from the `CompletedPipelineExecutor` poll, so `ClientBase::onProgress`, which is not thread-safe, ran on two threads at once. Forward progress only on the thread that called `sendQuery`; on other threads it stays in the atomic `state->progress` and reaches the client on its next poll or with the final `Progress` packet. Make `LocalQueryState::is_cancelled` atomic, as that callback sets it on a pipeline thread. The new test aborts under ThreadSanitizer in 20 of 20 runs without the fix and passes 20 of 20 with it; its `--processed-rows` count checks that the deferred progress still reaches the client (a variant that drops it changes the count in 20 of 20 runs). Under the flaky check's thread fuzzer one run takes at most 24 s. CI report (Stress test (arm_tsan), STID 1003-46d8): https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=100371&sha=9373f31b7d5da16c1af8cca79c27d546ab9c5d77&name_0=PR&name_1=Stress%20test%20%28arm_tsan%29 Related: ClickHouse#100371 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (3 rounds): 2 fixed, 1 dismissed
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261027-232700 |
|
cc @azat @yakov-olkhovskiy, could you review this and add the |
|
Workflow [PR], commit [0c46cee] Summary: ❌
AI ReviewSummaryPR #128019, reviewed at Missing context / blind spots
Final Verdict✅ Approve. No code changes requested; pending CI checks still need to complete. |
CI finish ledger - 0c46ceeEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The new Session id: cron:our-pr-ci-monitor:20261028-180006 |
d586d92
Related: #100371
Related: #100230
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
clickhouse-localand the embedded client no longer call the client's progress handler from pipeline threads.Description
Stress test (arm_tsan)on #100371 reports a data race inClientBase::onProgress: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=100371&sha=9373f31b7d5da16c1af8cca79c27d546ab9c5d77&name_0=PR&name_1=Stress%20test%20%28arm_tsan%29Since #100230, the interactive cancel callback that
LocalConnection::sendQueryinstalls also forwards accumulated progress to the client. Nested executors poll that callback (scalar subqueries, sets), and they run on pipeline threads when a query is analysed inside a running pipeline, for example the query of a materialized view with a scalar subquery over the view source, analysed for every inserted block. The client thread meanwhile calls the same progress handler from theCompletedPipelineExecutorpoll, soClientBase::onProgress, which is not thread-safe, runs on two threads at once.The callback now forwards progress only on the thread that called
sendQuery. On other threads the progress stays in the atomicstate->progressand reaches the client on its next poll or with the finalProgresspacket, so totals are unchanged and cancellation still works from any thread.LocalQueryState::is_cancelledbecomes atomic because that callback sets it on a pipeline thread.This is a ThreadSanitizer report in CI and no wrong result has been observed in a release, so the category is CI Fix.
Validation: under TSan the new test
05454_local_progress_from_pipeline_threadsaborts with this race in 20 of 20 runs without the fix and passes 20 of 20 with it;--processed-rowschecks that the deferred progress is still delivered (a variant that drops it changes the count in 20 of 20 runs); 50 randomized runs pass on a debug build.#125990 and #125610 carry the identical change; they merge cleanly in any order.
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/128019]
Version info
26.11.1.1186-master(included in26.11and later)