Repository navigation
Reapply "Do not wait for the remote drain when cancelling a remote query", with the cancel/finish race closed - #118696
Conversation
…ery" This reverts commit 29595ee, which reverted ClickHouse#118218 (merged as e3fb4a9). The reverted change fixes this: RemoteQueryExecutor::finish takes was_cancelled_mutex as its first statement and holds it across the packet drain, whose connections->receivePacket() is an uninterruptible socket read bounded only by receive_timeout (300 s by default). cancel() needs the same mutex and is driven from ExecutingGraph::cancel, which walks every processor under processors_mutex, so one draining remote source stalls the whole cancellation sweep: KILL QUERY can take up to receive_timeout to return, and the remote sources after the draining one are never cancelled at all, so other replicas keep running a query the initiator has already given up on. It surfaced as Stress test (arm_msan) / "Hung check failed, possible deadlock found". ClickHouse#118525 reverted it because 04340_distributed_plan_status_reenqueue_fault and 04648_distributed_plan_task_error_propagation began failing on master. Those two tests do not run any RemoteQueryExecutor: make_distributed_plan forces enable_parallel_replicas = 0, makeDistributed rejects ReadFromRemote, and assertFragmentSerializable rejects the rest, so the initiator pipeline has no RemoteSource, and neither cancel() caller tree-wide is reachable from a distributed-plan query. The failures are also reproducible on a tree that carries the revert and neither of the two fixes now open for them (39281bb fails both), so the defect they expose is pre-existing. The step change in their failure rate nevertheless tracks this change's presence on master, and I do not claim to have identified the carrier. This commit restores the reverted diff unchanged so the reapply is reviewable on its own. The next commit closes a hole the first attempt left: it published the drain flag after finish had already taken was_cancelled_mutex, so a cancel that read the flag earlier still waited out the whole drain. Related: ClickHouse#118218, ClickHouse#118525
The reverted change published its drain flag *after* `finish` had already taken
`was_cancelled_mutex` and run `tryCancel`, so this interleaving still waited out
the whole drain:
cancel: reads the flag as false -> falls through
finish: holds `was_cancelled_mutex`, not yet published (includes `tryCancel`)
cancel: takes `was_cancelled_mutex` -> waits out the drain
Publishing the flag earlier only shrinks that window: between `cancel` reading
the flag and acquiring the mutex a whole `finish` can publish, acquire and start
draining, which is reachable under the thread fuzzer this bug was reported from.
Closing it needs the observation and the acquisition to be atomic, so the flag
becomes `finish_in_progress`, a counter under a dedicated `finish_gate_mutex`
held for O(1) work only. `finish` increments it before asking for
`was_cancelled_mutex`; `cancel` reads it and takes `was_cancelled_mutex` while
still holding the gate, then releases the gate before `cancelUnlocked`.
Why that is atomic: a `cancel` that reaches the acquisition holds the gate and
has read zero. Any `finish` that already owns or is waiting for
`was_cancelled_mutex` incremented the counter first, so it would have been seen;
any `finish` that has not incremented yet is blocked at the gate and so cannot
own that mutex. The holder `cancel` may wait for is therefore never a draining
`finish`. `connections->receivePacket` has exactly two call sites: `read`, which
releases the mutex before it, and `finish`'s drain, so the drain is the only
place the mutex is held across a blocking read. The other holders are
`sendQuery` and `processPacket` (network writes), the async steps of
`readAsync`, which return an fd instead of blocking, `isCancelled` and the
destructor.
Deadlock freedom: the order is always `finish_gate_mutex` before
`was_cancelled_mutex`. `finish`'s `SCOPE_EXIT` is declared before its
`LockAndBlocker`, so at scope exit the mutex is released first and the gate is
taken afterwards, and `cancel` unlocks the gate explicitly. That unlock is
load-bearing rather than tidiness: `cancelUnlocked` reaches `tryCancel`, whose
`read_context->cancel` and `connections->sendCancel` are socket writes, and
holding the gate across them would make every concurrent `finish` wait for that
I/O at the gate instead. The gate covers a counter update, a comparison, or one
acquisition, never I/O.
A skipped `cancel` loses nothing. `cancelUnlocked` has three effects, and
`finish` covers all three: every path that reaches the drain has run
`tryCancel`, so the `Cancel` packet is sent and a `cancel` would early-return on
`was_cancelled`; every earlier return leaves `finished` or
`hasThrownException`, on which `cancelUnlocked` returns without acting; and the
external-table `is_cancelled` flags have no live reader, because their only
reader tree-wide is `ExternalTableSink::consume`, reached from
`sendExternalTables` inside `sendQueryUnlocked`, which requires the same mutex
`finish` is holding. A later `sendQuery` cannot make them live again either:
`sendQueryUnlocked` returns at once when `sent_query` is set, which it is on
every path that gets there. `cancel` reentering from inside `finish` on the same
executor now returns immediately where it used to self-deadlock on the
non-recursive mutex.
The cancellation the skip defers therefore lands in `finish`'s `tryCancel`,
which runs on every path that reaches the drain and is a socket write, not the
unbounded read. `QueryRunner::cancelAll`, the other `cancel` caller tree-wide,
does not need `cancel` to have acted: it sets its own `finished` flag and then
waits on its thread pool, and the executor it skipped is being terminated by the
`finish` that caused the skip. `HedgedConnections::sendCancel` retracts pending
replacement replicas inside itself, so it covers them identically whichever
caller drives it.
The one way to reintroduce the original symptom through this code would be to
hold the gate while a second `finish` waits for `was_cancelled_mutex`. It does
not: `finish` releases the gate before asking for that mutex, so a `cancel`
never queues behind a drain at the gate either.
`05076_remote_query_executor_cancel_during_drain.sh` grows a second scenario for
this ordering, on a single executor. Two failpoints make it deterministic:
one parks `finish` at the top of the function, before it announces itself, which
is the only way to make `cancel` arrive first, and one parks `cancel` holding
only the gate. Both are guarded by the same executor-local
`in_receive_packet_window` predicate the drain pause uses, because
`ExecutingGraph::cancel` calls `onCancel` on every source including already
finished siblings, and a sibling shard would otherwise consume the one-shot
park. The scenario asserts both directions: `finish` must not reach its drain
while `cancel` holds the gate, and the background `KILL QUERY` must complete
once the gate is released while the drain park is still armed. Both
observations invert under the two rejected designs, which is what the scenario
exists to measure.
Related: ClickHouse#118218, ClickHouse#118525
Each scenario was gated on the shared `failed` flag, so a failure in the first one suppressed the second entirely: with the `cancel` skip removed as a mutation check, scenario A failed and scenario B never started its query, which would hide a second regression behind the first. Each scenario now gates on whether its own failpoints armed.
`echo done > "$kill_done"` writes a word `shellcheck` reads as the loop keyword (SC1010), and the poll only tests for the file's existence, so `touch` says what is meant.
Review round 3 on the reapply. All of it is test scaffolding except the one guard in `finish`; no production behaviour changes. `remote_query_executor_finish_drain_hold` was the only one of the four pause failpoints here not guarded by `in_receive_packet_window`, so any shard's `finish` could consume the one shot the test is waiting for. The two comments in `05076` that call the drain park executor-local were therefore false as written, and the tree's own drift record said so while proving the property empirically instead. Guarding the injection makes them true by construction: `in_receive_packet_window` is set only while that executor's own reader is parked at `receive_packet_pause`, which is exactly the shard whose `finish` the test wants to catch. It also makes scenario A more deterministic, since today either shard can satisfy that wait. `max_threads` is pinned in the fixture. The randomizer draws 1 with p = 0.32, and while measurement says that does not break the test (10 runs with the pin removed drew 1 four times and all passed), the interleaving wants both shards' readers runnable at once, and that should not be left to a draw. The background `KILL` in scenario B recorded that its client had terminated, not that it had succeeded, so a `KILL` failing fast read the same as one that completed. It now records the client's status and the assertion requires 0, with the blocked and errored cases reported differently. Scenario B's first assertion likewise treated any non-zero status as its pass; it now requires `timeout`'s 124 and prints stderr on anything else. Every `SYSTEM WAIT FAILPOINT ... PAUSE` is bounded. Unbounded, a rig where the fixture cannot form left the test to be killed by the runner with no output at all; bounded, it names the failpoint that was never reached. This is the one item of this round I added rather than found prescribed, and the bare `wait` for the background query is still unbounded, so it buys the diagnosis and not yet a hang-free guarantee. One correction to the previous commit's caller census: besides `RemoteQueryExecutorRegistry::cancelAll`, a third driver reaches `RemoteQueryExecutor::cancel`, via `ReadFromRemote`'s read-completed callback to `IProcessor::cancel` and `RemoteSource::onCancel`, which cancels parallel replicas that went unused. It is covered: a `finish` that falls through reaches `tryCancel`, and every earlier return leaves `finished`, `hasThrownException` or `was_cancelled` set, on which `cancelUnlocked` does nothing.
Review round 4 on the reapply. Test only; no production behaviour changes. The previous round bounded every `SYSTEM WAIT FAILPOINT ... PAUSE`, but the three bare `wait` calls stayed unbounded, and on one path the test was guaranteed to hang rather than merely able to. `wait_pause` failing on `remote_query_executor_cancel_gate_hold` sets `sync_ok=0`, and the block that releases `remote_query_executor_finish_entry_hold` and the gate sits inside `if [ "$sync_ok" -eq 1 ]`, so both stayed armed. Only the drain hold and the receive pause were released unconditionally, and the next statement is a bare `wait`: the parked shard's `finish` was still parked at the entry hold, so its client never exited and the `wait` blocked until the runner killed the test, with no diagnosis at all. `cleanup` does release all four, but it is an `EXIT` trap and `EXIT` was never reached. Scenario A's `wait` also sits before its `system.text_log` positive control and `assert_query_gone`, so one stuck client silently suppressed both of those assertions too. This PR fixes a hung check, so a test that can hang would trade a fixed hung check for a fresh one. `release_all` releases all four failpoints, drain hold first and receive pause last so a woken reader finds connections already drained, and it is called at each of the three sites that precede a bare `wait`, including `cleanup`, whose inline loop it replaces. That also removes the two unguarded disables whose failure would have printed to stdout and broken the reference diff for an unrelated reason. Both background clients get `timeout 120`, which makes every bare `wait` provably terminate even if some future park were missed; 120 s is an order of magnitude above the whole test and above every individual bound in it, so it cannot pre-empt an assertion. No assertion changed: a `timeout` -killed `KILL QUERY` writes 124 to the sentinel, which the existing status branch already reports as a returned status. `wait_pause`'s own bound goes from 60 s to 30 s. `ci/jobs/fast_test.py` runs with `--shard --timeout 60` and this file is tagged `no-parallel, shard`, so a single 60 s wait would consume the entire per-test allowance there and the diagnostic it exists to print could never surface. The fixture forms in well under a second. Scenario B's negative wait goes from 10 s to 5 s, decided by measurement rather than taste. On a mutated tree that defeats the gate, the drain park is reached within 0.154 s of the entry hold being released, and the park is already established 4 us into the wait, so what is really being measured is one client round-trip; two samples, 0.150 s and 0.154 s. 5 s is over 30x that, and it takes the test from about 15.9 s to about 11.7 s, which is a fifth of the Fast test allowance returned. Verified in both directions with the release path as the only variable: with it removed the test hangs, killed at a 240 s bound I imposed, and the runner's own dump names the still-live fixture client; with it in place the test exits 1 in 36.0 s printing `cancel never reached the gate`. 50 randomized runs pass, in two batches of 25 with the second in `--order desc`, and the pinned `max_threads` is 2 on all 108 fixture queries while an unpinned setting takes 54 distinct values over the same queries.
Comments only. Stripping comments from both revisions of `RemoteQueryExecutor.h` and `RemoteQueryExecutor.cpp` gives identical text, so no token of code moved. The header said that on every earlier return from `finish`, `cancelUnlocked` "would also do nothing". That universal is false, in the diff's own load-bearing justification: `cancelUnlocked` sets `is_cancelled` on every entry of `external_tables_data` under `external_tables_mutex` before it reaches `if (finished || hasThrownException()) return;`, so on every path it does at least that. The summary now says which of `finished`, `hasThrownException` or `was_cancelled` `cancelUnlocked` would find already set, and claims nothing about what it then does. Why doing that much is harmless is argued in ee6e4b9, which names the flag's only reader tree-wide, and it stays there rather than being restated here. For the record, since the asymmetry invites the opposite change: hoisting `cancelUnlocked`'s external-tables block above the gate check in `cancel` would be wrong. `sendExternalTables` takes `external_tables_mutex` while holding `was_cancelled_mutex`, so `cancel` has to keep `was_cancelled_mutex` outermost. The current nesting is the correct one. `cancel`'s leading comment was four lines where three is the ceiling, and its first sentence cited another file's internals, `ExecutingGraph::cancel` and its `processors_mutex`. That citation is already in ee6e4b9's message. What remains is the local invariant a reader of `cancel` needs: `finish` can hold `was_cancelled_mutex` across an unbounded blocking read, this runs from a sweep that must not stall, and taking that mutex while still holding the gate is what makes the check meaningful.
Both prerequisite loops ran their second `wait_pause` even after the first had already failed. Once the first wait times out, `failed=1` and `sync_ok=0` are set and `wait_pause` has already named the failpoint that was never reached, so the second 30 s wait cannot add information. It only spends budget. Measured on a rig where one prerequisite failpoint is made unreachable, the run took 124.51 s and printed the diagnosis twice per scenario. Fast test runs `clickhouse-test` with `--timeout 60`, and `tests/clickhouse-test` arms `signal.alarm(int(args.timeout * 1.1) + 60)`, which is 126 s, as a hard backstop whose handler calls `stop_tests` and breaks the run loop. So a rig in which the fixture cannot form came within about a second and a half of abandoning the rest of the job rather than failing one test. Breaking at the first failed prerequisite takes the same rig to 64.94 s with one diagnosis per scenario. 64.94 s is still over Fast test's 60 s per-test allowance, and `proc.wait(args.timeout)` does not kill on expiry, so that job would report only "Timeout!" with no diagnosis: every message this test prints goes to stdout, while the failure description appends stderr. The test is therefore also tagged `no-fasttest`. Regular stateless jobs allow 600 s, which is where a test that synchronises four failpoints belongs. Nearby precedent for the same reason: `04839_parallel_replicas_cancel_before_announcement.sh` and `04340_distributed_plan_status_reenqueue_fault.sh`. No bound was reduced and no assertion changed. Both `break`s sit after `failed=1`, so a broken fixture still exits non-zero, and each is reachable only where `sync_ok=0` has already made the downstream assertions unreachable. 50 randomized runs of the result pass 50/50.
`err` was opened with truncation both by the backgrounded query client and by the foreground `arm`, `wait_pause` and `KILL QUERY` helpers, which run concurrently with it, so one could truncate a diagnostic the other had just produced. It could not change a verdict: every `cat "$err"` sits on a path that has already set `failed=1`, nothing is catted on the success path, and the reference file is never polluted by it. It is worth fixing while the file is open anyway, because the diagnostic it can lose is the one a broken rig depends on. Also corrects the ratio in `start_query`'s bound comment. The test takes about 11.7 s now, not the about 15.9 s it took when that comment was written, so 120 s is about 10x its duration rather than 8x.
Internal second-model reviewSix rounds over this re-land. Everything below was fixed before publishing; the dispositions worth
💡 Nothing observes a remote source other than the draining one being cancelled; the positive 💡 The background query client's stderr goes to its own file so it cannot truncate the diagnostics |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20260908-003900 |
|
Workflow [PR], commit [140127f] Summary: ✅
AI ReviewSummaryThis PR reintroduces the "do not wait for the remote drain on cancel" behavior by making Findings💡 Nits
Final Verdict
LLVM Coverage ReportMeasured on commit 02a0da1.
Changed lines: Changed C/C++ lines covered: 21/21 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units69 translation units recompiled, 763 s compile time in total, 69 of them have a recent master baseline. |
CI finish ledger - 86ad44eEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The
Session id: cron:our-pr-ci-monitor:20260908-083121 |
…on-cancel Conflicts in `FailPoint.cpp` and `RemoteQueryExecutor.cpp`: master (ClickHouse#119069, after the review request on ClickHouse#110334 that no test may park a pipeline worker inside `IProcessor::work`) removed the `remote_query_executor_receive_packet_pause` reader park and the `in_receive_packet_window` flag that guarded this PR's `finish` and `cancel` holds, replacing 04512's fixture with the inline `remote_query_executor_cancel_and_drain_in_receive_window`. Resolved by taking master's failpoint and dropping the reader park here too. The three holds stay, guarded by a new executor-local pin instead: `remote_query_executor_finish_entry_hold` fires once, and the executor that fires it sets `owns_test_holds`, so the drain hold and the cancel-gate hold can only be consumed by that executor and not by the sibling shard. Every `finish` entry of the pinned executor waits at the entry hold while it is armed, because `work` and `onUpdatePorts` can enter `finish` on different threads and a second one running ahead into the drain would defeat the interleaving. `05076` no longer arms the reader park; scenario A pins through the entry hold and releases it before waiting for the drain hold, scenario B is unchanged apart from the dropped park. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 Merged master (8d973b2) and resolved the conflicts in What conflicted. #119069 (after the review request on #110334 that no test may park a pipeline worker inside Resolution. Master's failpoint is kept and the reader park is dropped here too, so 05076 no longer parks a reader inside In 05076, scenario A now pins through the entry hold and releases it before waiting for the drain hold; scenario B is unchanged apart from the dropped reader park. The fix itself ( Verification (local RelWithDebInfo, arm64): 05076 and 04512 pass; 05076 passes 20/20 with randomized settings, longest run 26 s. Mutation arm with the One residual worth a human eye: the The remaining red, |
|
Thanks for the merge and the resolution. I read it at 1. The test flaked once in CI at this head. The entry hold fires and parks before 2. Your residual, taken literally: yes, and it applies to every run of this test rather than to a corner case. The fixture is Both points have one fix and I am doing it: rebuild the fixture with no park on an executor thread, in the shape #119069 already uses in this file ( |
`RemoteQueryExecutor::finish` runs from `RemoteSource::work` (`LIMIT 1` closes the output port, `prepare` returns `Finished`, `need_drain` is set) and also from `onUpdatePorts`. Both are pipeline executor worker threads, so `finish_entry_hold` and `finish_drain_hold` broke the contract in `src/Processors/IProcessor.h` on every run of this test rather than in a corner case: `notifyPauseAndWaitForResume` waits on a condition variable with no timeout that only another client statement can release, and scenario A's assertion depended on `KILL QUERY` not releasing it. ClickHouse#119069 had already dropped the reader park here for the same reason. The defect under test is a state, not an interleaving: `cancel` only has to run while a thread is inside `finish` holding `was_cancelled_mutex`. So the three `PAUSEABLE_ONCE` holds and the `owns_test_holds` pin are replaced by one `ONCE` failpoint that runs `cancel()` inline, on the draining thread itself, in the shape 04512 already uses at the reader. Nothing is parked, so the executor-local pin has nothing left to guard and the `std::atomic_bool` leaves the header. That also removes the flake the pin introduced. The entry hold fired before `++finish_in_progress` and pinned whichever executor entered `finish` first, with nothing keeping that executor's drain outstanding, so any of the three conditions in `if (!isQueryPending() || hasThrownException() || was_cancelled)` could become true under the park, after which the drain hold was unreachable (1 failure in 126 runs at 8d973b2). The predicate ClickHouse#119069 removed, `in_receive_packet_window`, could only be true while a reader was blocked mid-receive, that is, only for a shard that provably still had packets to drain. The fixture now carries that implication positively, through `distributed_push_down_limit=0`: by default each shard applies the `LIMIT` itself and sends `EndOfStream` after a single granule (measured 16384 rows read, against 200000 with the push-down off), so a `finish` that already observed `finished` returned before reaching the drain and the failpoint never fired. That was reproducible at 1 in 25 randomized runs before the pin. Both directions measured on this content, debug build: fixed: 50/50 randomized runs pass (two batches, the second in `--order desc`), plus 25/25 with `use_hedged_requests=1` forced. 1.44 s per run, against 11.3 s before. unfixed: with `cancel` reverted to its pre-PR body, FAIL at 61.5 s reporting `armed 1` and `consumed 0`, so the injection fired and the interleaving was established. `system.stack_trace` then shows the deadlock the gate prevents, including the production victim: `PullingAsyncPipelineExecutor::cancel` -> `ExecutingGraph::cancel` -> `RemoteSource::onCancel` -> `RemoteQueryExecutor::cancel` blocked on `was_cancelled_mutex` on the TCPHandler thread, behind the drain thread holding it. The fix itself, `finish_gate_mutex` and `finish_in_progress`, is untouched. Co-Authored-By: Claude Opus 5 <[email protected]>
…nt's lock-order exception Fast test installs `config.d/listen.xml` and `config.d/clusters.xml` unconditionally (`tests/config/install.sh`, outside the `FAST_TEST` guards), and `clickhouse-test` derives shard support from `listen_host` matching `127.0.0.2` or `::`, so this `shard`-tagged test does run there, against a 60 s per-test allowance. A 60 s client bound left a regression to be killed by the runner with a bare `Timeout!` instead of the scripted diagnosis. The query returns in 0.07 s wall, 0.012 s server-side, having drained 200000 rows, so 30 s keeps a ~400x margin while leaving the diagnosis and the cleanup inside the budget: the unfixed arm now fails at 31.3 s instead of 61.5 s, with the same message. The header's lock-order note claimed the reverse order never happens. Under the new failpoint it does: `finish` holds `was_cancelled_mutex` and the injected `cancel` then takes `finish_gate_mutex`. That is safe only because the counter is already non-zero there, so `cancel` returns before locking anything, which is worth stating instead of the absolute claim. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Done, pushed as What changed. The three Both arms, debug build, 05076.
The unfixed arm reproduces the deadlock in its production shape rather than only a self-lock. The flake had a second cause, the same one in substance. Dropping the park removed what used to guarantee an outstanding drain, which is what One thing this costs, and I could not get it back. Scenario B is gone, and with it the only coverage that distinguished this gate from the racy pre-check the revert removed: the inline
|
The test needs a `finish` that reaches its packet drain, and it got one only most of the time: `Stateless tests (amd_asan_ubsan, flaky check)` failed 1 of 25 at 480bd4a with `consumed 1`, i.e. the failpoint never fired and the run proved nothing. The failing run's server log says why. Neither shard logged "Cancelling query because enough data has been read", so neither `finish` got past its `!isQueryPending()` early return: both executors had already seen `EndOfStream` through `read()`. `LIMIT 1` does close the initiator's output ports, but what is left to drain by then depends on how many packets that close leaves behind, and blocks arrive granule-aligned on this path - `max_block_size = 1` clamps a block up to one granule, it does not split one. The runner randomizes `index_granularity` over [1, 65536]; at the 43695 it drew for that run each shard sent two data packets, few enough for `read()` to reach `EndOfStream` first. Across that job's 25 iterations, 3 had one shard miss and 1 had both, which is the failure. `index_granularity = 256` leaves ~390 packets per shard instead, and an explicit DDL setting wins over the randomizer's `--allow_merge_tree_settings`. The query is also retried while the failpoint is still armed, so a residual miss costs an attempt rather than the check; a regression still fails on the first attempt that fires. Measured on a server confined to two cores, which reproduces the CI rate: 8 misses in 150 runs before the pin, 0 in 150 after, plus 150 runs under the real harness with settings randomized per run. With the `finish_in_progress` check removed from `cancel`, the test fails in 31.1 s on "the query did not complete with cancel injected into finish's drain" with `consumed 0`, so the injection still establishes the interleaving it is there for. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Pushed What flaked. Why. In that job's server log neither shard logged Fix. Measured on a server confined to two cores, which reproduces the CI rate: 8 misses in 150 runs before the pin, 0 in 150 after. Then 175 runs under the real harness with settings randomized per run, all green, randomization confirmed active (176 distinct The fix itself ( |
CI finish ledger - ea5c7e4Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
Neither red is PR-caused. This PR touches Why #119867 owns the NATS shard: the wedge is the Session id: cron:our-pr-ci-monitor:20260917-013108 |
# Conflicts: # src/Common/FailPoint.cpp # src/QueryPipeline/RemoteQueryExecutor.cpp
|
🕵 Merged master into the branch and pushed it as
|
# Conflicts: # src/Common/FailPoint.cpp # src/QueryPipeline/RemoteQueryExecutor.cpp
The `failpoint_tests_are_isolated` style check (67965ab) requires every stateless test that arms a fail point to carry both `no-parallel` and `no-fasttest`. 05076 already had `no-parallel`; the master merge into this branch brought the rule in and `Style check` failed on it. The comment on the query's 30 s bound referred to Fast test's per-test allowance, which no longer applies; it now refers to the runner's per-test timeout. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #118218
Related: #118525
Related: #118390
Related: #118417
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed cancelling a distributed,
s3Clusteror parallel-replicasSELECTtaking up toreceive_timeout(300 s by default) to take effect, and never reaching some of the remote sources, when one of them was draining the packets left over after aLIMITwas satisfied.Description
Reintroduces #118218, as asked there: "Reverting. Please investigate and reintroduce".
Defect.
RemoteQueryExecutor::finishholdswas_cancelled_mutexacross its packet drain, whosereceivePacketis an uninterruptible socket read bounded only byreceive_timeout(300 s).cancelneeds the same mutex and runs fromExecutingGraph::cancel, which walks every processor underprocessors_mutex: one draining source stalls the whole sweep, soKILL QUERYcan takereceive_timeoutto return and later sources are never cancelled.Commit 1 restores #118218 unchanged. Commit 2 fixes what it got wrong: it published the flag only after
finishhad taken the mutex, so acancelthat read it earlier still waited out the drain. The flag becomes a counter under afinish_gate_mutexheld for O(1) work:finishincrements it before asking forwas_cancelled_mutex, andcancelholds the gate across its own acquisition of that mutex, so observation and acquisition are atomic.05076gains a scenario for that order and reddens under both rejected designs.I did not instead release
was_cancelled_mutexacross the drain:read,readAsyncandprocessPackettake it too, andonUpdatePortscan run while another thread executes the node, so that would admit two threads into onereceivePacket.The two tests that caused the revert. Neither runs a
RemoteQueryExecutor:make_distributed_planforcesenable_parallel_replicas = 0, leaving noRemoteSourcein the initiator pipeline. And the revert did not stop them: in the check carrying most of their failures the rate did not move across it, and five post-revert heads that fail both have the revert as an ancestor and carry neither this flag nor05076. So this change is not their carrier. Their onset is sharp and unexplained; #118390 and #118417 are the open fixes, so the ordering is your call.One residual: no assertion covers the never-cancelled later source, because in a two-shard fixture each shard's own
finishcancels it first.Provenance, and the rate across the revert: 38 / 414 after, 40 / 466 before (click to expand)
Asked for in #118218 (comment). Observed as
Hung check failed, possible deadlock found:https://s3.amazonaws.com/clickhouse-test-reports/PRs/112359/c71c9c0c46c419ef30aa8d39dcb4bf22f38d2e5b/stress_test_arm_msan/hung_check.log
04340and04648combined inStateless tests (arm_asan_ubsan, azure, sequential), from 2026-08-25, measured 2026-09-08 01:45Z:Master ran that check only 42 times after the revert, so the master column cannot settle it. The PR column can, and its rate did not move.
Post-revert heads failing both tests that have the revert as an ancestor, with neither
drain_in_progress/finish_in_progressinRemoteQueryExecutor.hnor the05076path present:39281bbd8cfeae30(#116647),d566ff4c5d1711c1(#118569),8beed835fbfbda86(#118628),6384a606bec90a85(#118620),b17c035435d1522b(#118629).#116647's own diff touches only
StorageMergeTreeCodecBlockCountsand its table function, nothing in the distributed-plan, exchange or cancellation path.Workflow [PR]
Sync PR [sync-upstream/pr/118696]
Version info
26.10.1.1482-master(included in26.10and later)