Skip to content

Do not render the client progress into a canceled terminal buffer - #127834

Merged
alexey-milovidov merged 6 commits into
masterfrom
fix-progress-canceled-tty
Oct 30, 2026
Merged

alexey-milovidov merged 6 commits into
masterfrom
fix-progress-canceled-tty

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

When the terminal of the client embedded into the server (SSH, Web Terminal) is gone, a failed write cancels tty_buf and reports the error, but the client keeps receiving progress packets. ProgressIndication::writeProgress then writes into the canceled buffer, which raises a LOGICAL_ERROR (Cannot write to canceled buffer), an abort in debug and sanitizer builds:

DB::WriteBuffer::throwWriteToCanceledBuffer
DB::ProgressIndication::writeProgress   src/Common/ProgressIndication.cpp:175
DB::ClientBase::onProgress
DB::ClientBase::receiveEndOfQueryForInsert
DB::ClientBase::processInsertQuery
...
DB::ClientBase::runInteractive
DB::ClientEmbedded::run
DB::ClientEmbeddedRunner::clientRoutine

This change skips rendering the progress indication and the progress table (writeProgress, clearProgressOutput, writeTable, clearTableOutput) into a canceled buffer. All of them run under tty_mutex, so the check cannot race with the write that cancels the buffer.

The Stress test (amd_debug, SharedCatalog, meta in keeper) of the CH Inc sync of the PR that randomizes the protocols of the Stress test found it.

Related: #125517
Related: #125973
Related: #126142

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):

Fix a LOGICAL_ERROR Cannot write to canceled buffer in the server when the terminal of an SSH or Web Terminal session is closed while the embedded client shows the progress of a query.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.904-master (included in 26.11 and later)

When the terminal of the client embedded into the server (SSH, Web Terminal)
is gone, a failed write cancels `tty_buf` and reports the error, but the
client keeps receiving progress packets, and `ProgressIndication::writeProgress`
then writes into the canceled buffer, which is a `LOGICAL_ERROR`
(`Cannot write to canceled buffer`) from `ClientBase::receiveEndOfQueryForInsert`.
Skip rendering the progress indication and the progress table into a canceled
buffer.

Found by the Stress test with randomized protocols:
#125517

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [167183a]

Summary: ✅


AI Review

Summary

This PR prevents progress rendering and cleanup from writing into a canceled terminal buffer after an embedded client disconnects, and adds an INSERT disconnect regression. Both prior findings are addressed; no new actionable findings remain. The regression passes the current-head Fast test and passed 50 iterations in the preceding ARM ASan/UBSan run.

Missing context / blind spots
  • ⚠️ Targeted and sanitizer jobs for head 167183ad5d9cb9016395eaca0fd033cbd12241ca are still pending. Their completed reports would confirm the remaining current-head CI coverage; no tests were run locally during this review.
Final Verdict

Status: ✅ Approve. No code changes requested.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Oct 26, 2026
Comment thread src/Common/ProgressIndication.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-cli clickhouse-client (interactive CLI) and client library. label Oct 26, 2026
@azat azat self-assigned this Oct 27, 2026
alexey-milovidov and others added 2 commits October 27, 2026 10:43
The write of the progress into the gone terminal fails and cancels the
terminal buffer, then `processInsertQuery` cancels the query and
`receiveEndOfQueryForInsert` keeps receiving the progress. Without the guards
of the previous commit, the test reports `Cannot write to canceled buffer`
(and aborts the server in debug builds); with them, it passes.

Address review: #127834

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…05453_webterminal_close_during_insert`

The predicate also matched the `executeQuery` debug entries carrying the text of the checking
query itself and of its parallel runs in the flaky check, so the expected zero became 3..32.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=127834&sha=244ae25e5ce661b3a17225662a6f3679f2afca94&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20targeted%29
#127834

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 167183ad5 with master 7fc4e86ed (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

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

Job report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks ok.

@alexey-milovidov alexey-milovidov self-assigned this Oct 30, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 30, 2026
Merged via the queue into master with commit 553f228 Oct 30, 2026
180 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-progress-canceled-tty branch October 30, 2026 08:05
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocker This issue / pr blocks a new release comp-cli clickhouse-client (interactive CLI) and client library. 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