Repository navigation
Conversation
…failed `ReadBuffer::next` cancels the buffer when the read fails, and a canceled buffer cannot be read again. When the terminal on stdin is closed while the client asks whether to output a binary format, reading the answer fails with EIO. Since ClickHouse#127912 the output format is created again for the next block of the result, which asks the question again and reads the canceled `std_in`: `LOGICAL_ERROR` "ReadBuffer is canceled" in debug and sanitizer builds (STID 2508-2bbd, the web terminal on master). `ask` now returns the default answer without asking when its input is canceled. The new test runs the client with stdin and stdout on two separate terminals and closes the one on stdin at the question. A client that starts reading only after the terminal is gone reads EOF instead of failing and exits with 0; that run does not reach the failed read, so the test repeats it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The canceled input gives the default answer "N", so the result must not be printed. Without this check, the test would also pass if the canceled input were answered with "y". Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (click to expand)
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20261028-205800 |
|
cc @azat @Avogar, could you review this and add the |
|
Workflow [PR], commit [3bc9335] Summary: ✅
AI ReviewSummaryThis PR prevents reads from canceled client input in Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units9 translation units recompiled, 29 s compile time in total, 9 of them have a recent master baseline. |
…macOS The test needs reading the answer from the closed terminal on stdin to fail. On macOS such a read returns EOF instead (xnu `ptsread` reads nothing once the master side is closed), and the client was killed by SIGHUP: `Fast test (arm_darwin)` got exit code -1 instead of 74. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - ed4b314Every 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:20261029-033003 |
| bool ask(std::string question, ReadBuffer & in, WriteBuffer & out) | ||
| { | ||
| /// A failed read cancels `in`, and nothing can be read from it after that: assume the default answer. | ||
| if (in.isCanceled()) |
There was a problem hiding this comment.
@groeneai I see a while (true) right after this. Are you sure the check is only needed here?
There was a problem hiding this comment.
Check if this is needed elsewhere
There was a problem hiding this comment.
The loop is fine: ReadBuffer::next cancels the buffer when the read throws and rethrows it, so a failed read leaves ask with that exception, and EOF gives an empty answer, i.e. "N". The std::cin overload already returns false when !std::cin.good().
It was needed in the other readers of std_in, fixed in fb32def and 3bc9335:
isStdinNotEmptyAndValidreturns false when reading stdin fails, and its next call read the canceled buffer:clickhouse-local --async_insert 1 -q "...; INSERT INTO t VALUES (1); INSERT INTO t VALUES (2)" 0>/dev/nullaborts on master. Now it returns false without reading.- With
--ignore-error, after the failed read of the answer, anINSERTreading its data from that terminal read it again:sendDataFromStdinin the client, and theinput()initializer ofLocalConnectioninclickhouse-local. Both throwNO_DATA_TO_INSERTnow.
Tests: 05465_client_unreadable_stdin_checked_twice (master 10/10 abort, fix 50/50 OK), and a second part of 05464 for the INSERT readers (removing either check fails it).
|
@groeneai 🕵️ Thanks, the fix and the test look right. An input that can't be read anymore should get the default answer. The cause sits one level up, though. After a
Once a local format error has cancelled the query, the client only needs to drain the remaining packets. For example, |
|
Acknowledged. I'll open the follow-up PR that makes the client only drain the remaining packets after a local format error, and post its link here. |
`isStdinNotEmptyAndValid` returns false when reading stdin fails with `CANNOT_READ_FROM_FILE_DESCRIPTOR`, and that failed read cancels `std_in`. The next check in the same run (another INSERT) read the canceled buffer, which aborts debug and sanitizer builds with "ReadBuffer is canceled. Can't read from it.". Same defect as in `ask`, in the other reader of `std_in`. Reproduced with `clickhouse-local --async_insert 1` running two `INSERT ... VALUES` with stdin open for writing only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ailed After reading the answer to the binary-format question failed (the terminal on stdin was closed), `--ignore-error` runs the next queries, and an INSERT that reads its data from stdin read the canceled `std_in`: `sendDataFromStdin` in the client, and the `input()` initializer of `LocalConnection` in `clickhouse-local`. Both now fail with `NO_DATA_TO_INSERT` instead, like an INSERT without data on stdin. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The follow-up is open: #128238 (after a local format error the client only drains the rest of the result). |
…lient After a `LocalFormatError` (the client failed to create or write its output format), `receiveResult` sends `Cancel` but kept passing every remaining `Data` / `Totals` / `Extremes` packet to `onData` / `onTotals` / `onExtremes`. When the error came from `initOutputFormat`, `output_format` is null afterwards, so every remaining block built the output again: the pager was started again, the `INTO OUTFILE` file was opened again, and a failure that went away mid-result left an output with a gap while the client still exited with the first error. Since ClickHouse#127912 the binary-format question is asked again too, reading the stdin the first failed answer canceled (`LOGICAL_ERROR 'ReadBuffer is canceled'`, STID 2508-2bbd on master). A per-query flag is set where a `LocalFormatError` is created (the three sites: `initOutputFormat`, the write in `onData`, the background error check in `receiveResult`), checked at the top of the three result callbacks, and reset in `processParsedSingleQuery`. Setting it at the origins instead of in `receiveResult` also covers the `INSERT ... RETURNING` drain (`receiveEndOfQueryForInsert` calls the callbacks directly). `cancelled` is not reused: it would disable the receive timeout and Ctrl+C handling in the drain loop, skip waiting for the pager and print "Query was cancelled.". Requested by @PedroTadim in ClickHouse#128090 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The client no longer reads its stdin again after a read from it failed: it does not ask the binary-format question again after the terminal on stdin was closed, and the next queries get
NO_DATA_TO_INSERTinstead of readingINSERTdata from it.Description
Related: #127912
Since #127912 (master only, not in any release), closing the terminal on the client's stdin while it asks "Do you want to output it anyway? [y/N]" for a binary output format leads to
LOGICAL_ERRORReadBuffer is canceled. Can't read from it., an abort in debug and sanitizer builds. In the web terminal the server aborts: STID 2508-2bbd, master CI.Root cause: the failed read (EIO) cancels
std_in. #127912 resetsoutput_formatwheninitOutputFormatfails, andreceiveResultkeeps processingDatapackets after theLocalFormatError, so the next block creates the format again, asks the question again and reads the canceled buffer.The other readers of
std_indo the same:isStdinNotEmptyAndValid(the check forINSERTdata on stdin, false when the read fails) on its next call, e.g.clickhouse-local --async_insert 1with twoINSERT ... VALUESand stdin open for writing only, and with--ignore-errora laterINSERTreading its data from stdin (sendDataFromStdin, and theinput()initializer ofLocalConnection).Change: on a canceled input,
askreturns the default answer ("N") without asking,isStdinNotEmptyAndValidreturns false, and the twoINSERTreaders throwNO_DATA_TO_INSERT.Validation: the new test
05464_client_binary_format_question_after_stdin_closedruns the client with stdin and stdout on two terminals and closes the stdin one at the question. Without the fix the question is printed twice and the client aborts (10/10); with the fix it is printed once, no result is printed, and the client exits with the read error, code 74 (50/50 with randomized settings and-j 8). Removing the check, or answeringy, makes it fail. The test also runs anINSERTfrom that terminal after the failed read, in the client and inclickhouse-local; removing eitherINSERTcheck makes it fail.05465_client_unreadable_stdin_checked_twiceaborts on master (10/10) and passes with the fix (50/50). The existing terminal and web terminal tests pass.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/128090]