Repository navigation
Mark a query as cancelled in the process list when its TCP client cancels it - #127149
Conversation
Since ClickHouse#126555 moved the test into the parallel pool, the ParallelReplicas lane reports `Some queries hung` on master (2 of 21 runs). The table has one mark; when a remote replica reads it, the whole 300 s `sleepEachRow` block runs in a secondary query with its own query_id. The test's `KILL QUERY WHERE query_id = ...` kills only the initial query, and `sleep` stops only when its own query is killed, so the secondary outlives the test and the end-of-run hung check catches it. Parallel replicas add nothing to what the test checks (KILL QUERY interrupting the DETACH DATABASE wait), so tag it `no-parallel-replicas`: the lane skips it and other lanes run it with enable_parallel_replicas = 0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261021-095500 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261021-093100 |
|
cc @KochetovNicolai, could you review this and add the |
|
Workflow [PR], commit [11687c0] Summary: ❌
AI ReviewSummaryThe PR propagates native TCP client cancellation and connection failures to the query's process-list entry before joining pipeline workers, allowing operations such as Final VerdictStatus: ✅ Approve |
CI finish ledger - 9ef712cEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The two Session id: cron:our-pr-ci-monitor:20261021-190007 |
|
@groeneai I feel we should fix the code, not the test. Also, why did this start failing recently all of a sudden? The test isn’t new |
ClickHouse#127935 restored the `no-parallel` tag until this PR lands. With this PR the parallel replicas follower of the killed `SELECT` stops sleeping, so the test can run in the parallel pool again (requested in ClickHouse#127935). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since it runs in the parallel pool, the remote part of its killed `SELECT` keeps sleeping and the hung check reports `Some queries hung`. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=127038&sha=9f841c9ae9a312abac66b6136e939dc248c3a7a3&name_0=PR PR: ClickHouse#127038 Related: ClickHouse#127149 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A client that dies while it receives a result is often first noticed on a write (`sendData`, `sendInteractiveUpdates`, `out->sync`), not by the socket poll, and a failed write leaves `stop_query` unset. `processOrdinaryQuery` then joined the executor with the process list entry still not cancelled, so a `sleepEachRow` stream kept running (reported by clickhouse-gh on ClickHouse#127149, reproduced 3/3: still in `system.processes` 12 s after SIGKILL, `is_cancelled = 0`). A failed write cancels `out` (`WriteBuffer::next`), so `killQueryIfStoppedByClient` now also acts when `out` is canceled. Worker thread callers reach it only with `stop_query` already set, so `out` is read only on the connection thread or under `callback_mutex`. The query keeps the network exception (`NETWORK_ERROR` in `query_log`). 05452 gains `select, client killed`: a UNION ALL whose fast stream keeps the server writing while the other sleeps, the client SIGKILLed, and a large `interactive_delay` so the write is what notices it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The CI test profile (`tests/config/users.d/limits.yaml`) sets `max_rows_to_read = 20000000`, so the `select, client killed` case's `numbers(1000000000)` stream failed at once with TOO_MANY_ROWS. The query never appeared in `system.processes`, `wait_for_query` spent its 60 s, and the test ran into the 60 s per-test budget of the Fast test. The case needs a stream that is still sending when the client is killed, so set `max_rows_to_read = 0` for this query only. Measured with `limits.yaml` installed on the local server: the unchanged test reproduces the CI output (`query did not start: ..._select_killed`, 76 s); the fixed test passes on the fix binary 19/19 (random settings, no random settings, `limits_fast.yaml`) plus 20/20 under load, and still fails on the binary without the write-side fix, only on `select, client killed: still running` (3/3). Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 11687c0Every 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:20261027-223005 |
Algunenano
left a comment
There was a problem hiding this comment.
Looks good. Most code changes are new blocks to catch exceptions, so it's quite simple even though it looks large
d47efca
|
@groeneai This new test takes 16 seconds (https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=129052&sha=latest&name_0=PR&name_1=Fast+test+%28arm_darwin%29). It should be faster and/or removed from fast test. Please handle it |
|
Acknowledged. I'm investigating |
…bles_on_failure The test filled the user's only max_concurrent_queries_for_user slot with a long sleepEachRow query and killed its client after 5 s, relying on the orphaned query to keep running so that the next SELECT 1 fails with TOO_MANY_SIMULTANEOUS_QUERIES before its external tables are read. Since ClickHouse#127149 the server cancels a query whose TCP client is gone, and sleep stops at its next 1 s chunk, so the slot is free before SELECT 1 arrives. Sanitizer builds lose that race every time (master red in amd_tsan, amd_msan and amd_asan_ubsan integration tests), arm_binary usually wins it. Hold the slot with a background request whose client stays connected, wait until it is in system.processes, run the unchanged SELECT 1, then stop the holder with KILL QUERY ... SYNC. The log assertions that are the purpose of the test are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
This test was reverted together with this PR (#129310), so the speed-up went to the re-land instead: groeneai/ClickHouse@a2e73c1, offered for #129311 in #129311 (comment). It takes about 5 s instead of 18 s in Fast test. |
Related: #126555
Related: #127935
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
When a client cancels a query over the native protocol or disconnects, the query is now also marked as cancelled in the process list, as
KILL QUERYdoes. Work that checks only that, such assleep, now stops promptly, including in the remote part of a distributed,*Clustertable function or parallel replicas query whose initiator was cancelled, and in anINSERTwhose client cancels it or disconnects while still sending data.Description
04117_detach_database_kill_queryfailsStateless tests (arm_binary, ParallelReplicas, s3 storage, parallel)withSome queries hungsince #126555 moved it to the parallel pool; the hung row is its parallel-replicas follower,is_cancelled: 0. #127935 restored itsno-paralleltag meanwhile; this PR removes it.Root cause: when the client cancels a query over TCP (a
Cancelpacket or a dropped connection),TCPHandlercancels the pipeline executor and waits for its threads, but never marks the query as cancelled in the process list.sleepchecks only the process list entry (QueryStatus::checkTimeLimit), so a cancelled query sleeps out its whole block, here 300 s.Change: before the executor is cancelled,
TCPHandler::killQueryIfStoppedByClientcancels the process list entry with the current exception, keeping the client's error, when the client cancelled or a write to it failed. It is called inprocessOrdinaryQuery, in the interactive cancel callback (covering pipelines insideexecuteQuery, likeCREATE TABLE ... AS SELECT), in theinput()reader and the cluster function and parallel replicas read task callbacks, and inprocessInsertQuerybefore the pushing executor joins. A dropped connection during anINSERTnow setsstop_query.AsyncInsertQueueTransformlogs a killed query's exception from its fallback pipeline at debug level. Two OpenTelemetry tests drop a redundant secondKILL QUERY.Validation: the new
05452_cancel_by_client_stops_sleep(the remote part afterKILL QUERY, also of aurlClusterquery whose read task request receives theCancel;INSERT SELECT, a streamedINSERT,CREATE TABLE ... AS SELECTandINSERT SELECT FROM input()cancelled byclickhouse-client; a streamedINSERTand aSELECTwhose client is killed) fails without the fix (every case still running after 60 s) and passes with it. Locally under ParallelReplicas the 04117 follower is gone within 11 s in 20/20 runs (before: 0/20). 04117, 04869, 05025 and 05452 pass repeated runs with--hung-check, and02357_query_cancellation_racepasses withasync_insert = 1.Workflow [PR]
Sync PR [sync-upstream/pr/127149]
Version info
26.11.1.1264-master(included in26.11and later)