Repository navigation
Fix abort in LocalConnection::sendCancel when no query is running (web terminal, SSH, clickhouse-local) - #127364
Conversation
`LocalConnection::finishQuery` resets `state`, and the next `receivePacket` reports `EndOfStream`. `ClientBase::processInsertQuery` calls `sendCancel` from its `catch (...)` for any exception, including one thrown after the query is over (an `INSERT` whose `SELECT` names `input` without reading it gets `EndOfStream` instead of a sample block; in the stress test of ClickHouse#125517 the web terminal closed at the end of an `INSERT` and the progress-line write to the dead PTY threw). `sendCancel` dereferenced the empty optional and libc++ hardening aborted: `clickhouse-local` itself, or the whole server for the embedded client of the web terminal and SSH (STID 2360-3d86). Every other `LocalConnection` entry point already treats an empty `state` as "no query in flight", and `TCPHandler` ignores a `Cancel` between queries. Make `sendCancel` do the same; the original exception is still reported. 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-10:20261022-092000 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261022-090400 |
|
cc @azat @yakov-olkhovskiy, could you review this and add the |
|
Workflow [PR], commit [d72ee5c] Summary: ✅
AI ReviewSummaryThe PR makes The regression test passes in the current head's Fast test. The original fix also passed 50 debug regression runs. Final VerdictStatus: ✅ Approve. |
CI finish ledger - 59b54c3Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261023-013007 |
|
@groeneai 🕵️ Looks good. One optional follow-up: bool LocalConnection::pullBlock(Block & block)
{
if (state->executor)
...
}
void LocalConnection::finishQuery()
{
next_packet_type = Protocol::Server::EndOfStream;
if (state->executor)
...
}They don't seem reachable once a query is over, so this isn't a bug today. Since |
Both are reached only from `poll`, which returns early when `state` is empty, so the assertion holds by construction. It turns a future misuse into a clear assertion failure in debug builds instead of an abort on an empty `std::optional`. Suggested in review. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks. Added |
`LocalConnection` released the query state (the `BlockIO` that owns the process list entry, and the `QueryScope` of the client thread) only in `finishQuery` (the `EndOfStream` path), in the next `sendQuery`, or when the connection was destroyed. A query that failed after `executeQuery` returned delivered its `Exception` packet and kept its state, so in the web terminal and the SSH interface it stayed in `system.processes` while the session was idle at the prompt: it counted toward `max_concurrent_queries_for_user`, and `KILL QUERY ... SYNC` on it did not return. In the Stress test a leaked web terminal session kept such a query listed for 45 minutes and failed the hung check. Reset the state when the `Exception` packet is handed to the client, as `finishQuery` does for `EndOfStream` and as `TCPHandler` does with its per-query state. `sendCancel` can now be reached with no query (the catch of `ClientBase::processInsertQuery`), so it ignores the cancel then, with the same guard as ClickHouse#127364. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #125517
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed an abort of
clickhouse-local, and of the whole server for web terminal and SSH sessions, when anINSERTfailed after its query had already finished, for example anINSERTwhoseSELECTnames theinputtable function without reading it.Description
On 26.3.33.24,
echo 1 | clickhouse local --query "INSERT INTO FUNCTION null('x UInt64') WITH unused AS (SELECT * FROM input('x UInt64')) SELECT 1 FORMAT CSV"aborts (optional operator-> called on a disengaged value) instead of reporting an error. On master the same query typed into the web terminal aborts the server.Found by the stress test of #125517, which drives load through the web terminal: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125517&sha=2b0d93f14784862cba71e73227b2368f107e9a23&name_0=PR&name_1=Stress%20test%20%28amd_debug%29 (
Received signal 6, STID 2360-3d86). There the WebSocket closed at the end of anINSERT, and the write of the progress line to the dead terminal threw.Root cause:
LocalConnection::finishQueryresetsstate, andClientBase::processInsertQuerycallssendCancelfrom itscatch (...)for any exception, including one thrown after the query is over.LocalConnection::sendCanceldereferencedstateunconditionally, whilepoll,receivePacketand the destructor already treat an emptystateas "no query in flight".Fix:
sendCancelreturns when there is no query, the same wayTCPHandlerignores aCancelpacket between queries. The original exception is still reported.Validation: the new test aborts (exit 134) on the master binary and passes 50/50 with the fix. The web terminal repro aborts a master server and leaves the fixed server serving queries.
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/127364]
Version info
26.11.1.861-master(included in26.11and later)