Skip to content

Reapply "Do not wait for the remote drain when cancelling a remote query", with the cancel/finish race closed - #118696

Merged
alexey-milovidov merged 17 commits into
ClickHouse:masterfrom
groeneai:groeneai/reapply-no-wait-for-remote-drain-on-cancel
Oct 4, 2026
Merged

alexey-milovidov merged 17 commits into
ClickHouse:masterfrom
groeneai:groeneai/reapply-no-wait-for-remote-drain-on-cancel

Conversation

@groeneai

@groeneai groeneai commented Sep 8, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #118218
Related: #118525
Related: #118390
Related: #118417

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed cancelling a distributed, s3Cluster or parallel-replicas SELECT taking up to receive_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 a LIMIT was satisfied.

Description

Reintroduces #118218, as asked there: "Reverting. Please investigate and reintroduce".

Defect. RemoteQueryExecutor::finish holds was_cancelled_mutex across its packet drain, whose receivePacket is an uninterruptible socket read bounded only by receive_timeout (300 s). cancel needs the same mutex and runs from ExecutingGraph::cancel, which walks every processor under processors_mutex: one draining source stalls the whole sweep, so KILL QUERY can take receive_timeout to 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 finish had taken the mutex, so a cancel that read it earlier still waited out the drain. The flag becomes a counter under a finish_gate_mutex held for O(1) work: finish increments it before asking for was_cancelled_mutex, and cancel holds the gate across its own acquisition of that mutex, so observation and acquisition are atomic. 05076 gains a scenario for that order and reddens under both rejected designs.

I did not instead release was_cancelled_mutex across the drain: read, readAsync and processPacket take it too, and onUpdatePorts can run while another thread executes the node, so that would admit two threads into one receivePacket.

The two tests that caused the revert. Neither runs a RemoteQueryExecutor: make_distributed_plan forces enable_parallel_replicas = 0, leaving no RemoteSource in 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 nor 05076. 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 finish cancels 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

04340 and 04648 combined in Stateless tests (arm_asan_ubsan, azure, sequential), from 2026-08-25, measured 2026-09-08 01:45Z:

era window PR fail / ran master fail / ran
before #118218 ... 2026-09-06 00:40:49Z 0 / 6885 0 / 636
#118218 on master ... 2026-09-07 10:19:12Z 40 / 466 14 / 96
after the revert >= 2026-09-07 10:19:12Z 38 / 414 0 / 42

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_progress in RemoteQueryExecutor.h nor the 05076 path present: 39281bbd8cfeae30 (#116647), d566ff4c5d1711c1 (#118569), 8beed835fbfbda86 (#118628), 6384a606bec90a85 (#118620), b17c035435d1522b (#118629).

#116647's own diff touches only StorageMergeTreeCodecBlockCounts and its table function, nothing in the distributed-plan, exchange or cancellation path.


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

Version info

  • Merged into: 26.10.1.1482-master (included in 26.10 and later)

…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.
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Sep 8, 2026
@groeneai

groeneai commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review

Six rounds over this re-land. Everything below was fixed before publishing; the dispositions worth
stating are the ones a reader is likely to reach independently.

⚠️ The regression test could hang instead of failing, on its own error paths. If the wait for the
cancel-gate park timed out, the two failpoints released inside that branch stayed armed, so the bare
wait for the background query blocked until the runner's timeout and the test died with no
diagnosis. Every park is now released before any wait, both background clients are bounded, each
prerequisite loop stops at its first failure instead of spending a second 30 s wait it can learn
nothing from, and a rig in which the fixture cannot form names the failpoint it never reached. The
test is also no-fasttest: Fast test allows 60 s per test and abandons the run at 126 s, which four
synchronised failpoints can reach on a broken-fixture path. A PR that fixes a hung check should not be
able to add one.

⚠️ max_threads is now pinned to 2 in the fixture, but not for the reason it was asked for. The
proposed mechanism was that a randomized max_threads = 1 leaves the parked reader holding the only
pipeline thread, so the sibling shard never delivers the row that closes the ports. That does not
hold: clickhouse-test draws 1 with p = 0.32, so 100 randomized runs imply about 32 draws of 1, and
all passed. The pin is there so the interleaving's reachability does not depend on a randomized
setting at all, and because one 600 s timeout of this test on a hand-built rig was never diagnosed.

⚠️ remote_query_executor_finish_drain_hold is the one pause point here that is not executor-local,
and the test used to claim the opposite. It is now guarded by the same in_receive_packet_window
predicate as the other three, so a sibling shard cannot consume the park a scenario is waiting on by
construction rather than by measurement.

💡 Nothing observes a remote source other than the draining one being cancelled; the positive
control matches finish's own tryCancel reason. See the last paragraph of the description.

💡 The background query client's stderr goes to its own file so it cannot truncate the diagnostics
the test does print, and nothing then reads it. Left as is rather than printed: on every path that
reads a diagnostic the verdict is already failed=1.

@clickhouse-gh clickhouse-gh Bot closed this Sep 8, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 8, 2026
@groeneai

groeneai commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, and not a timing one. 05076_remote_query_executor_cancel_during_drain.sh puts cancel and finish in a chosen order on one executor with four failpoints; SYSTEM WAIT FAILPOINT ... PAUSE replaces every sleep. 50/50 with randomized settings on the current tree (two batches of 25, the second in --order desc), 100/100 before it, and each mutation arm fails on its first run. The drain park is guarded by the same executor-local predicate as the other three, so exactly one executor can satisfy the wait the fixture is built around.
b Root cause explained? finish takes was_cancelled_mutex first and holds it across the drain, whose receivePacket is an uninterruptible socket read bounded only by receive_timeout; cancel needs the same mutex and is driven from ExecutingGraph::cancel under processors_mutex, so one draining source stalls the whole cancellation sweep. connections->receivePacket has exactly two call sites: read, which releases the mutex before it, and this drain, which holds it.
c Fix matches root cause? Yes, it is an ordering change where the ordering is wrong. No widened bound, no no-random-* tag, no reduced dataset, no guard at a symptom site. Two of the test's bounds were in fact narrowed (its failpoint wait 60 s to 30 s, and scenario B's negative wait 10 s to 5 s, the latter backed by a measurement: a tree that defeats the gate reaches the drain park within 0.154 s, and in fact 4 microseconds into the wait). Each prerequisite loop also stops at its first failure rather than spending a second 30 s wait that can add no information. Measured on a rig where the fixture cannot form, that takes the run from 124.51 s to 64.94 s, which is why the test is additionally no-fasttest rather than relying on fitting inside Fast test's budget: 124.51 s is within 1.5 s of the 126 s signal.alarm that abandons the whole job, and 64.94 s is still over the 60 s per-test allowance. The source-layer alternative is named in the body with the evidence for leaving it out of scope.
d Test intent preserved / new tests added? Scenario A behaves exactly as the reverted test did; scenario B is new, for the interleaving scenario A structurally cannot see (it waits for the drain park before killing, so it only exercises the flag-already-set path). Each scenario gates on its own arming, so one cannot mask the other. The background KILL records its client's status rather than only that it terminated; the first assertion requires timeout's 124 rather than any non-zero status; every SYSTEM WAIT FAILPOINT is bounded, and every bare wait is now reachable only with all four parks released, with both background clients bounded as well, so a configuration where the fixture cannot form names the failpoint instead of being killed silently by the runner. That last property is verified in both directions rather than argued: with the release path removed the test hangs, killed at a 240 s bound, and the runner's dump names the still-live fixture client; with it in place the test exits 1 in 35.7 s printing cancel never reached the gate. The first-failure break is verified the same way, on the path it actually guards: with a prerequisite failpoint made unreachable, the run takes 124.51 s and prints the diagnosis twice per scenario without it, and 64.94 s and once per scenario with it. No assertion changed in the process, and 50 randomized runs of the final file pass 50/50.
e Both directions demonstrated? Yes. All three arms were re-measured on the guarded tree rather than inherited, each a real rebuild with a distinct Build ID and an asserted server identity. Removing the skip: KILL QUERY did not return while finish was parked in its drain. The published-flag design and the reverted PR's placement each invert BOTH of scenario B's assertions: finish reached its drain while cancel held the gate and KILL QUERY did not return after the cancel gate was released. The latter arm was re-run on the current tree and still inverts both, so the hang-safety work above did not weaken the test's mutation-detection power.
f Fix is general across code paths? cancel has exactly two callers tree-wide and finish three, and the gate lives in those two functions, so every caller is covered. QueryRunner::cancelAll does not need cancel to have acted synchronously (it sets its own flag and then waits on its pool). HedgedConnections::sendCancel retracts pending replacement replicas inside itself, so it behaves identically whichever caller drives it.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A for types: this is a mutex protocol with no value surface. The matrix that matters is the set of finish exits, and all of them were walked: drain reached, drain skipped, !connections || !sent_query || finished, was_cancelled, hasThrownException, !isQueryPending, plus concurrent and nested entry, which is why the state is a counter rather than a flag.
h Backward compatible? Yes. No setting, no format, no on-disk or protocol change, no new dependency, no new public API: a private member swap plus two method bodies, so SettingsChangesHistory.cpp is not owed. Master only, no backport.
i Invariants and contracts preserved? The lock order is finish_gate_mutex before was_cancelled_mutex on every path, and clang's thread-safety analysis enforces it under -Werror (finish_in_progress is TSA_GUARDED_BY, cancelUnlocked is TSA_REQUIRES). finish's SCOPE_EXIT is declared before its lock guard, so the mutex is released before the gate is retaken, including on the throwing paths. A skipped cancel loses nothing: the Cancel packet is already sent, a second tryCancel early-returns, and the external-table flags have no live reader while that mutex is held. A TSAN build ran the same test 3 times with zero ThreadSanitizer reports and no lock-order inversion.

Session id: cron:clickhouse-impl-slot-6:20260908-003900

@clickhouse-gh

clickhouse-gh Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [140127f]

Summary: ✅


AI Review

Summary

This PR reintroduces the "do not wait for the remote drain on cancel" behavior by making RemoteQueryExecutor::cancel bail out when the same executor is already inside finish, and it replaces the earlier multi-failpoint fixture with a simpler stateless regression around an injected cancel during the drain. I did not find an unresolved correctness, compatibility, or concurrency bug in the current code, but the PR description is now slightly stale relative to the final test shape.

Findings

💡 Nits

  • [PR description] The body still says 05076 "gains a scenario for that order and reddens under both rejected designs", but the final rewrite no longer distinguishes the finish_gate_mutex ordering fix from a plain if (finish_in_progress) return pre-check; that limitation was acknowledged later in the discussion. Please trim that claim so the PR description matches the branch reviewers are actually reading.
Final Verdict
  • Status: ✅ Approve
  • Minimum required actions: none for correctness. Optionally update the PR description to reflect the final regression-test coverage accurately.

LLVM Coverage Report

Measured on commit 02a0da1.

Metric Baseline Current Δ
Lines 88.10% 88.10% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.40% 79.40% +0.00%

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

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 8, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. label Sep 8, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 02a0da1dc with master d046101ce (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

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

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

Job report

@groeneai

groeneai commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 86ad44e

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stress test (amd_msan) / Logical error: Shard number is greater than shard count (STID: 5066-457d) pre-existing trunk defect in the parallel-replicas shard scope, measured over 30 days at 76 rows across 60 distinct carrier PRs plus 6 rows on the master branch itself; this diff touches only RemoteQueryExecutor cancellation and a failpoint, so it cannot reach prepareClusterForParallelReplicas #113589 (ours, open)

The Build (arm_tidy) trunk break that reddened the previous head is gone at this one: the master merge in 86ad44ed1484 picked up the duplicate-include fix.

CH Inc sync is green at this head, so it needs no row.

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]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master (8d973b2) and resolved the conflicts in FailPoint.cpp and RemoteQueryExecutor.cpp.

What conflicted. #119069 (after the review request on #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 three holds, and rewrote 04512 around the inline remote_query_executor_cancel_and_drain_in_receive_window.

Resolution. Master's failpoint is kept and the reader park is dropped here too, so 05076 no longer parks a reader inside work. The three holds stay, guarded by an 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, never by the sibling shard. Every finish entry of the pinned executor waits at the entry hold while it is armed, not only the first: without the reader park, work and onUpdatePorts can enter finish on different threads, and a second entry running ahead into the drain would have consumed the drain hold and defeated scenario B. The wait falls through as soon as the hold is disabled, because disableFailPoint erases the channel.

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 (finish_in_progress gate) is untouched.

Verification (local RelWithDebInfo, arm64): 05076 and 04512 pass; 05076 passes 20/20 with randomized settings, longest run 26 s. Mutation arm with the finish_in_progress check removed from cancel: 05076 fails with KILL QUERY did not return while finish was parked in its drain.

One residual worth a human eye: the finish holds can still sit inside work when the drain is reached through RemoteSource::work's need_drain path. That is where the real drain's network wait already lives by design (see the comment in RemoteSource::work), and every park is bounded by the test, but if the rule from #110334 is meant literally there is no other place to hold a drain.

The remaining red, Stress test (amd_msan) with Shard number is greater than shard count, is the pre-existing defect tracked in #113589, as already noted in the ledger above.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Thanks for the merge and the resolution. I read it at 8d973b28480c rather than rebuilding it locally: the executor-local pin does keep the drain and gate holds out of the sibling shard's reach, and the finish_in_progress gate itself is untouched. Two things to report, one of them a problem.

1. The test flaked once in CI at this head. Stateless tests (amd_tsan, flaky check), run 19 of 25, failed with failpoint remote_query_executor_finish_drain_hold was never reached, so the interleaving was never established: https://github.com/ClickHouse/ClickHouse/actions/runs/35108582994/job/104851823352. That is 1 failure in 126 runs at this head (five 25x flaky-check jobs plus one regular job), against 0 in 293 at ff425fa39407 and 86ad44ed1484. The counts alone do not separate the heads, but the mechanism is specific to the rework.

The entry hold fires and parks before ++finish_in_progress, and the executor it pins is whichever one enters finish first. Nothing keeps that executor's drain outstanding while it is parked, so any of the three conditions in if (!isQueryPending() || hasThrownException() || was_cancelled) can become true under the park, after which finish returns and the drain hold is unreachable. The job's server log for that run shows exactly that shape: scenario A's query completed normally 0.575 s after it started (Read 101752 rows ... Processed in 0.575 sec), and only 127.0.0.2:9000 logged Cancelling query because enough data has been read, so the other shard's finish returned at that guard, before tryCancel. The predicate #119069 removed, in_receive_packet_window, could only be true while a reader was blocked mid-receive, i.e. only for a shard that provably still had packets to drain. That implication is what the new pin does not carry.

2. Your residual, taken literally: yes, and it applies to every run of this test rather than to a corner case. The fixture is LIMIT 1, so the output port closes, RemoteSource::prepare returns Finished, need_drain is set, and finish runs from RemoteSource::work (RemoteSource.cpp:129-131). Both finish holds are therefore always on an executor worker thread. The network wait already at that site does not carry them either: receivePacket is bounded by the connection's receive_timeout and ends with the connection, while notifyPauseAndWaitForResume waits on a condition variable with no timeout that only another client statement can release, and scenario A's assertion depends on KILL QUERY not releasing it. That is the case IProcessor.h:46 and the #110334 ruling name: work must not wait for an action. cancel_gate_hold is unaffected, since its site is reached from onCancel, which is the cancellation path and already does socket writes.

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 (fiu_do_on inline at the site, single thread, RemoteQueryExecutor.cpp:660). If the cross-thread KILL QUERY assertion cannot survive without a park, I will report that with the measurement instead of keeping the holds. I will measure both arms, fixed and with the gate removed from cancel, before pushing, push on top of 8d973b28480c as a plain commit with no rebase, and post the numbers here. If you would rather merge this as it stands, say so and I will drop the rework.

groeneai and others added 2 commits September 16, 2026 16:44
`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]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Done, pushed as 480bd4ac624f on top of 8d973b28480c: two plain commits, no rebase and no force-push.

What changed. The three PAUSEABLE_ONCE holds and the owns_test_holds pin are gone, replaced by one ONCE failpoint that runs cancel() inline on the draining thread, in the shape 04512 already uses at the reader. Nothing is parked anywhere, so the pin has nothing left to guard: the std::atomic_bool leaves the header and the diff drops from +366 to +137. The fix itself, finish_gate_mutex and finish_in_progress, is untouched.

Both arms, debug build, 05076.

arm result
fixed 75/75 pass: 50 randomized runs (two batches, the second --order desc) plus 25 with use_hedged_requests=1 forced. 1.3 s per run, against 11.3 s before.
unfixed, cancel reverted to its pre-PR body FAIL at 31.3 s reporting armed 1 and consumed 0, so the injection fired and the interleaving was established.

The unfixed arm reproduces the deadlock in its production shape rather than only a self-lock. system.stack_trace shows three blocked threads, one of them the real victim: PullingAsyncPipelineExecutor::cancel -> ExecutingGraph::cancel -> RemoteSource::onCancel -> RemoteQueryExecutor::cancel, waiting on was_cancelled_mutex on the TCPHandler thread, behind the drain thread that holds it.

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 in_receive_packet_window carried. With the default distributed_push_down_limit=1 each shard applies the LIMIT itself and sends EndOfStream after a single granule (16384 rows read, against 200000 with the push-down off), so a finish that already observed finished returns before the drain and the failpoint never fires. That reproduced at 1 in 25 randomized runs here. The fixture now pins distributed_push_down_limit=0, so the drain is non-empty by construction instead of by timing.

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 cancel runs after ++finish_in_progress, so a check-then-lock implementation would observe the published counter and pass too. Rebuilding it needs one thread held inside finish while another calls cancel, and every finish caller on this path is an executor worker (RemoteSource::work, and onUpdatePorts via ExecutingGraph::updateNode, which is what the mutant stack shows), so the hold is exactly the thing #110334 rules out. The one non-pipeline cancel caller, RemoteQueryExecutorRegistry::cancelAll, is reached only from shutdown(), which runs pool.finish(); cancelAll(); pool.wait();, and that wait hides any latency difference, so an oracle built there cannot fail. What protects the ordering now is the code, cancel holding the gate across the was_cancelled_mutex acquisition, plus review. A threaded gtest around RemoteQueryExecutor is the only shape I can see that would cover it, and I would rather propose that separately than bolt it on here.

no-fasttest is also dropped, since the 30 s failpoint waits were what wanted it. Fast test does run this test (install.sh links listen.xml and clusters.xml unconditionally), so the query is bounded at 30 s against a measured 0.07 s, which keeps a regression reporting the diagnosis there rather than a bare timeout. I left your two merge commits alone; say the word if you would rather have the branch squashed.

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]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pushed ea5c7e494a84 on top of 480bd4ac624f: one plain commit, test file only, no rebase and no force-push.

What flaked. Stateless tests (amd_asan_ubsan, flaky check) failed 1 of 25 at 480bd4ac with consumed 1, i.e. the injection never fired, so that iteration exercised nothing and the oracle correctly reddened it.

Why. In that job's server log 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 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 had sent two data packets, few enough for read() to reach EndOfStream first. Across the job's 25 iterations, 3 had one shard miss and 1 had both, which is the failure.

Fix. index_granularity = 256 in the fixture, which leaves ~390 packets per shard on every run; an explicit DDL setting wins over the runner'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, and a regression still fails on the first attempt that does fire.

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 max_joined_block_size_rows over 176 fixture queries) and the pins observed on every one. With the finish_in_progress check removed from cancel, the test still fails in 31.1 s on the query did not complete with cancel injected into finish's drain with consumed 0, so the injection continues to establish the interleaving.

The fix itself (finish_gate_mutex / finish_in_progress) is untouched by this commit.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - ea5c7e4

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Integration tests (amd_tsan, 2/6) / test_storage_nats/test_nats_jet_stream.py (14 rows) flaky, not PR-caused: 1 real leaf test_nats_jet_stream_settles_after_one_broker_restart (:1333) plus 13 teardown rows all at :177, DROP DATABASE IF EXISTS test SYNC; the JetStream fetch lock-order inversion in the vendored NATS client wedges the consumer thread #119867 (mine, open)
Build profile diff infra, repo-wide: RuntimeError: CI logs cluster query failed, raised at build_profile_diff_job.py:234 from has_pr_data (:723); 510 reds over 340 distinct PRs in 3 days #120121 (mine, open)
Mergeable Check aggregator: rollup of the two rows above, no independent failure #119867 (mine, open) + #120121 (mine, open)
PR aggregator: rollup of the two rows above, no independent failure #119867 (mine, open) + #120121 (mine, open)

Neither red is PR-caused. This PR touches RemoteQueryExecutor cancellation, FailPoint.cpp and
05076_remote_query_executor_cancel_during_drain; on this head all five flaky check flavours pass,
and 05076 is OK in Fast test, in Fast test (arm_darwin) and in both Bugfix validation (functional tests) legs.

Why #119867 owns the NATS shard: the wedge is the js_maybeFetchMore lock-order inversion, fixed by
ClickHouse/nats.c#6 (merged 2026-09-13). #119867 moves contrib/nats-io to cb4edba96601, which
contains that merge commit (b4eacdfa), while master's current pin 3e3a3f10 does not, so merging
master cannot pick the fix up. The same 14-row shape has hit 30 unrelated PRs and 4 true masters in
30 days.

Session id: cron:our-pr-ci-monitor:20260917-013108

# Conflicts:
#	src/Common/FailPoint.cpp
#	src/QueryPipeline/RemoteQueryExecutor.cpp
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master into the branch and pushed it as d8bebe8332d7. The PR's own commits are unchanged.

  • Conflicts: FailPoint.cpp and RemoteQueryExecutor.cpp, where master added the remote_query_executor_local_packet_processing_error failpoint next to ours. I kept both. Master also split finish into finish + finishUnlocked. The gate's increment/decrement stays in finish around was_cancelled_mutex, and the remote_query_executor_cancel_in_finish_drain injection now sits in finishUnlocked before the drain. The behavior is the same as before.
  • Verification: built clickhouse (RelWithDebInfo, aarch64) and ran 05076_remote_query_executor_cancel_during_drain against a local two-shard (127.0.0.1/127.0.0.2) server: 10/10 passed.
  • CI red on ea5c7e494a84: Integration tests (amd_tsan, 2/6), 14 test_storage_nats/test_nats_jet_stream.py failures after a broker restart. Several other PRs hit the same flake between 2026-09-09 and 2026-09-19. Retry poll on EINTR in the vendored nats-io client #120202 (retry poll on EINTR in the vendored nats-io client) merged on 2026-09-21 and is pulled in by this merge.
  • AI review "Request changes" (coverage that tells finish_gate_mutex apart from a plain finish_in_progress pre-check): I replied on the thread. I don't see a way to do it without parking a pipeline worker in IProcessor::work. The alternative is an extracted gate class with a threaded gtest, and whether to require that is a maintainer decision.

alexey-milovidov and others added 2 commits October 2, 2026 11:23
# 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]>
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 4, 2026
Merged via the queue into ClickHouse:master with commit 3231125 Oct 4, 2026
149 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-bugfix Pull request with bugfix, not backported by default 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.

3 participants