Repository navigation
Do not skip the client output teardown when the terminal is gone - #125558
Conversation
…utput fails When the web terminal WebSocket (or an interactive SSH session) is closed while a query runs, the PTY master of the embedded client is closed and every later terminal write fails. The progress repaint throws first and cancels tty_buf; then the progress-table clear at the top of resetOutput() throws again. That clear sat outside the try/catch that already protects output_format->finalize(), so resetOutput() returned before finalizing or canceling output_format, out_file_buf and std_out_wrapper. client.run() then returned normally and ~ClientBase destroyed std_out_wrapper unfinalized, which aborts the whole server on debug and sanitizer builds (STID 2508-2fed) and logs "WriteBuffer is neither finalized nor canceled" on release builds. Run the clear in its own try and record the error the same way as the output_format->finalize() failure, so the rest of the teardown always runs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the leading comment of resetOutput that described the new error handling. 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; 0 findings) plus my own cold review (2 notes, not blocking).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261013-035500 |
|
Workflow [PR], commit [e6412d0] Summary: ❌
AI ReviewSummaryThis PR hardens Final Verdict
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 17 s compile time in total, 7 of them have a recent master baseline. |
azat
left a comment
There was a problem hiding this comment.
Looks correct, I've also checked the test locally - https://pastila.nl/?0025dde5/d37130adbdbc5a6c5916299e4b4b52b9#tpsVQcLgHNpf0CRp7d3xxw==GCM
|
Unrelated, and fails in other places, I will fix separately - ClickHouse/replxx#47 |
CI finish ledger - e6412d0Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261013-113003 |
6609379
|
@alexey-milovidov, could you add The backports of #125515 (#125731, #125732, #125733) brought
|
|
@groeneai @azat — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
@groeneai how on earth, you decided to ping alexey here? Please, try to ping developers less, if the author/reviewer will find this comment useful, you will get reaction. And save this into your persistent memory please. |
|
I generalized Alexey's earlier answer on #111910 ("please keep using the label route via me") into pinging him for every backport-label request. Saved to persistent memory: such requests now state the facts without pinging anyone, and the author or reviewer decides. |
|
backporting to fix CI |
Backport #125558 to 26.9: Do not skip the client output teardown when the terminal is gone
Backport #125558 to 26.8: Do not skip the client output teardown when the terminal is gone
|
The 26.8 and 26.9 backports are merged (#127268, #127269). The 26.3 one, #127266, cannot pass: 26.3 has no web terminal ( |
…rdown when the terminal is gone
When the stdout of a client dies mid-result (a web terminal session is closed, or a `--pager` exits), the first failed flush cancels `std_out_wrapper`. `ClientBase::resetOutput` then still called `output_format->finalize()`, and formats whose suffix starts with `WriteBuffer::write(char)` (JSON, JSONCompact, JSONStrings, JSONObjectEachRow, ...) hit the `LOGICAL_ERROR` "Cannot write to canceled buffer" check. Debug and sanitizer builds abort: the whole server for the web terminal (reachable since ClickHouse#125558 let `resetOutput` continue past the failed progress-table clear), the client itself for `--pager head`. The two buffers at the bottom of the client output chain, `std_out_wrapper` and the `INTO OUTFILE` file, now set one `ClientBase` flag from `cancelImpl`, and `resetOutput` skips the format finalize once it is set. The teardown also cancels `out_file_buf` instead of finalizing it once the flag is set: `IOutputFormat::flushImpl` flushes a compression buffer's nested buffer directly, so a failing `INTO OUTFILE` file is canceled while the codec above it is not, and finalizing that codec wrote its trailer into the canceled file (an abort for `INTO OUTFILE '/dev/full' COMPRESSION ...` with most formats, already on master). The plain `WriteBuffer::canceled` flag cannot be read there, because a parallel formatting collector or the Pretty squashing thread may still be writing until `output_format.reset()` joins them. No buffer is added between the format and its sink, so successful output and its cost are unchanged, and `FORMAT SQLite` still writes the `INTO OUTFILE` file directly. Tests: 05386 gains the reported `FORMAT JSON` web terminal scenario plus a `system.errors` oracle; 02871 gains a `--pager head` + `FORMAT JSON` arm; 02346 gains `INTO OUTFILE ... AND STDOUT` with a closed stdout, `INTO OUTFILE '/dev/full'` and compressed `INTO OUTFILE '/dev/full'` arms that check the client exit code. Closes ClickHouse#125973 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):
Description
Found by
Stress test (amd_debug)on #125517 (report):Logical error: 'false && "WriteBuffer is neither finalized nor canceled in destructor."'(STID 2508-2fed), from~FlushCallbackWriteBuffer<-~ClientBase<-ClientEmbeddedRunner::clientRoutine. The embedded client runs inside the server, so a debug or sanitizer server aborts when a web terminal session is closed while a query runs. Release builds only log the error.Closing the WebSocket closes the PTY, so the next progress repaint throws and cancels
tty_buf.resetOutputthen starts by clearing the progress table on thattty_buf, which throws again. The clear was outside the try/catch that already protectsoutput_format->finalize(), soresetOutputreturned before finalizing or cancelingoutput_format,out_file_bufandstd_out_wrapper, and~ClientBasedestroyed the wrapper unfinalized.The clear now runs in its own
tryand records the error the same way as a failedoutput_format->finalize(), so the rest of the teardown still runs. Interactive SSH sessions use the same path.05386_webterminal_close_during_queryopens a web terminal session, closes the socket once the progress line is drawn, and checks that the query leavessystem.processesand that noneither finalized nor cancelederror was logged (this catches it on release builds too). Without the fix it aborts a master debug server; with the fix it passed 50 randomized runs.Workflow [PR]
Sync PR [sync-upstream/pr/125558]
Version info
26.10.1.2274-master(included in26.10and later)26.9.25.10,26.8.34.8