Repository navigation
Fix hang in --queries-file / -q when stdin is a pipe with no data - #96494
Conversation
`ClientBase::sendData` eagerly called `isStdinNotEmptyAndValid` to check if stdin had additional data for INSERT queries. This function calls `!std_in.eof()` which performs a blocking `read()` on stdin. When stdin is a pipe that has no data and hasn't been closed (common in CI, Docker, subprocess environments), the read blocks indefinitely. This caused the stress test crash (signal 11) for test `03538_analyzer_scalar_correlated_subquery_fix` because the process hung on `read(0, ...)`, then was killed by timeout. The fix: - Make the stdin check lazy (lambda) so it's only evaluated when needed - Skip the stdin check entirely when INSERT has inline data — inline data terminated by semicolon is already complete - Remove blocking stdin check in async insert path too https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=b9e68f4b9b0b33c7db43b00afb3eff4ff2050694&name_0=MasterCI&name_1=Stress%20test%20%28amd_debug%29 Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Workflow [PR], commit [a268c52] Summary: ✅
AI ReviewSummaryPR #96494, head Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block. Define an explicit stdin-source policy that preserves a way to consume supported delayed stdin without making complete inline inserts hang, apply it consistently to the inline/async guards, and add the focused regression coverage above. The dismissed threads remain closed. |
The previous commit made `isStdinNotEmptyAndValid` lazy and removed stdin handling after inline INSERT data and in the async insert path. This fixed the hang but broke two tests: - `02270_stdin_with_query_or_infile_data` (stdin + inline data) - `02884_async_insert_native_protocol_1` (async insert mixed data detection) Instead, add a `non_blocking` mode to `isStdinNotEmptyAndValid` that uses `poll` with zero timeout to check if stdin has data available before committing to the blocking `read` in `eof`. This avoids the hang on empty pipes while preserving all existing stdin functionality. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…false Separate the error handling in the non-blocking stdin check: - `EINTR`: retry the `poll` call - `ret == -1` (other errors): throw `ErrnoException` instead of returning false - `POLLERR`/`POLLNVAL`: throw with revents info - `ret == 0` (no data available): return false (the intended non-blocking path) Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The non-blocking `poll` is a point-in-time snapshot, so very-late-arriving stdin data could be missed. Document that this only affects the rare combined-source pattern (INSERT with INFILE or inline data + additional piped stdin), while the common stdin-only INSERT path is unaffected because `sendDataFromStdin` is called unconditionally. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Instead of using `poll(timeout=0)` which introduces a race condition (late-arriving stdin data could be missed), simply skip the stdin check entirely when the INSERT query already has inline data or INFILE. The blocking `read()` in `isStdinNotEmptyAndValid` hangs when stdin is a pipe without data/EOF (stress tests, CI, Docker, `--queries-file`). The combined-source pattern (inline data + stdin) was the only case affected; when there is no inline data or INFILE, `sendDataFromStdin` is called unconditionally. This addresses the review feedback about the `poll(timeout=0)` race and is a simpler, more correct solution. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
When INSERT already has inline data or INFILE, use `poll(timeout=0)` to check if stdin also has data, instead of calling the blocking `isStdinNotEmptyAndValid` which does `read(0, ...)`. This prevents indefinite hangs when stdin is a pipe without data/EOF (common in stress tests, CI, Docker, `--queries-file` mode). When there is no other data source (no inline data, no INFILE), the blocking check is kept — that is the existing behavior where stdin is the only source and we must wait for it. This also restores the async insert mixed-data check: when `is_async_insert_with_inlined_data` is true, we use the non-blocking poll to detect stdin data and throw `NOT_IMPLEMENTED` if found. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…taAvailableNonBlocking` Retry `poll` on `EINTR` instead of throwing, since signal delivery is normal during stdin probing. Surface `POLLERR`/`POLLNVAL` as an exception instead of silently returning false. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
… pipe Verifies that `--queries-file` with INSERT having inline VALUES does not hang when stdin is a pipe with no data and no EOF (the original bug scenario from stress tests and CI environments). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The test opened a FIFO on fd 3 (`exec 3<>"$FIFO"`), but shell_config.sh sets `BASH_XTRACEFD=3` for bash tracing. This caused bash trace output to be written into the FIFO, which the client then read as stdin data for INSERT, producing a parse error. Use fd 4 instead to avoid the conflict. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Address review feedback: add test coverage for `async_insert=1` with inline INSERT data and stdin as an empty pipe. The async insert path has its own stdin check that must also use non-blocking poll. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix. |
|
🕵 Merged |
`POLLERR` does not imply that no bytes remain readable: a socket whose peer sent data and then reset the connection reports `POLLIN | POLLERR | POLLHUP`, and the data is still readable. `getStdinStateNonBlocking` returned `EndOfFile` in this case, so already-available stdin input was ignored and inline/async inserts bypassed the mixed-input rejection. Check `POLLIN` before `POLLERR`/`POLLHUP`; keep `POLLNVAL` and error-only as end of file. Add a regression case with a TCP socket as stdin reset by its peer. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=96494&sha=0627229ef06a4486cbdf98bbcc79c4cbad16811d&name_0=PR&name_1=Build%20profile%20diff and provide a fix in a separate PR. If the fix is already in progress, link it here. The |
|
The The fix in progress is my open PR #126200: a readiness probe that the server rejects for its own load (exception code 202 or 241) ends the job green with |
|
🕵 Merged |
|
🕵 The only CI failure on head |
…rt-queries-file Resolve conflict in `ClientBase::sendData`: master now skips the stdin check entirely for `INSERT ... FROM INFILE`; keep that and apply this PR's non-blocking check only for inline data.
|
🕵 Merged |
|
🕵 Merged |
|
🕵 Merged |
|
🕵 Merged |
|
🕵 Fixed the |
|
🕵 The only red check on head |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=4 K_base=27 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
ClientBaseeagerly calledisStdinNotEmptyAndValidto check for trailing stdin data on everyINSERT. That helper calls!std_in.eof(), which performs a blockingread(0, ...). When stdin is a pipe that is open but has no data and noEOF(common in CI, Docker, stress tests, and--queries-fileinvocations), the read blocks indefinitely and the client hangs until it is killed by timeout.Concretely, this caused an exception (signal 11 after timeout) in the stress test
03538_analyzer_scalar_correlated_subquery_fix: the process hung onread(0, ...)and was killed.The fix replaces the eager blocking probe with a non-blocking one:
poll(timeout=0)first asks "does stdin appear to have data right now?", and only when it does we fall through toisStdinNotEmptyAndValidto confirm and consume it. This:pollreturns 0 immediately;inlined data + stdinmixed input — when stdin actually contains data (the case asserted by04064_inline_insert_data),pollreturnsPOLLINand we still throwNOT_IMPLEMENTED;(sleep 1; echo) | clickhouse-client ...) may not have written by the timepollruns, in which case the trailing stdin payload is ignored. This is preferable to the alternative of a hard hang, and is documented in the helper.Covered cases (
is_async_insert_with_inlined_data,is_inline_insert_data, and the appending-stdin path insendData) all go through the same probe so the hang is closed for--queries-file,-q, and--inline-insert-datamodes.CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=b9e68f4b9b0b33c7db43b00afb3eff4ff2050694&name_0=MasterCI&name_1=Stress%20test%20%28amd_debug%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a hang in
clickhouse-clientforINSERTqueries in--queries-file/-q/--inline-insert-datamode when stdin is an open pipe with no data and noEOF(common in CI, Docker, and stress tests).Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/96494]
Version info
26.12.1.161-master(included in26.12and later)