Repository navigation
Conversation
toString/CAST to String of a composite value (Dynamic, Array, JSON, ...) runs a per-row loop in ConvertImplGenericToString that calls serializeText for every row. The query time and cancellation limits are only checked between pipeline blocks, so a single large block kept a thread serializing for a long time after KILL QUERY or max_execution_time, which the server-side AST fuzzer repeatedly hit as "Hung check failed, possible deadlock found" (SerializationDynamic::serializeTextQuoted -> SerializationArray::serializeText -> ConvertImplGenericToString). The loop now checks for cancellation per row via QueryStatus::throwIfKilled (a cheap atomic load that throws QUERY_WAS_CANCELLED / TIMEOUT_EXCEEDED once the query is cancelled; timeouts flip the flag via CancellationChecker), so the query stops promptly. The QueryStatus is taken from the query context in FunctionConvertSettings and is null for the context-less castColumn() path, where there is nothing to cancel. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-6:20260703-042500 |
|
cc @Avogar @rschu1ze — could you review this? It makes the per-row |
|
Workflow [PR], commit [f6a1ad2] Summary: ❌
AI ReviewSummaryThis PR adds per-row timeout and cancellation polling to the generic composite-to-text conversion loops used by Findings
Final Verdict
|
bc is not installed on the Fast test runner, so the elapsed-time comparison wrote 'bc: command not found' to stderr and the test failed. awk already runs on that line and does the float subtraction natively, so drop the external bc dependency. The prompt-vs-blocked discrimination (d < 2) is unchanged. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Fix-up pushed (2986e0f): the new test Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-6:20260703-083300 |
…test The per-row cancellation check in ConvertImplGenericToString used QueryStatus::throwIfKilled(), which only observes state set by cancelQuery() (KILL QUERY and the `throw` timeout overflow mode). For timeout_overflow_mode = 'break', CancellationChecker::cancelTask() calls checkTimeLimit() and never sets is_killed, so the per-row poll stayed a no-op for the whole serialize loop and max_execution_time was not honored in that mode. Switch to QueryStatus::checkTimeLimit(), which throws for KILL/`throw` and returns false for `break`; turn the `break` result into a hard stop since a half-serialized value is not a useful partial result (same pattern as FunctionBaseXXConversion and sleep()). Rewrite 04401 to gate on a phase-specific signal instead of assuming a fast KILL means success. It measures the natural (unlimited) run time, sets max_execution_time to ~45% of it (past input building, inside serialization), and asserts from query_log that the query stopped near the limit rather than running to natural completion; it fails loudly if the query finished early (e.g. a randomized limit or an unrelated failure) or ran to the end (cancellation not observed inside serialization). Covers both `throw` and `break` modes and adds no-random-settings since the assertion is timing-based. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Pre-PR validation gate for the review-fix commit ae3bdc2 (honor Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-5:20260703-092800 |
The per-row cancellation check only polls between rows, so a single row holding one huge Array/Map/JSON/Dynamic value stays inside one serializeText() call (the container serializer's own inner loops) and was still uninterruptible by KILL QUERY / max_execution_time. Interpose a small fixed-size cancellation-checking WriteBuffer between the serializer and the column buffer. Every byte the (arbitrarily nested) serializer emits flushes through it at a fixed cadence, where it checks the query time/cancellation limit before forwarding to the real buffer. This needs no changes to any Serialization class and gives a bounded, value-size-independent latency (the existing WriteBufferFromVector doubles its buffer, so a check there would leave a gap of ~half the value's size). 04401 now also covers a single giant composite value with max_block_size=1, asserting it stops near the limit instead of running to natural completion, in both throw and break modes. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Pre-PR validation gate for dbc4f6a (interrupt serialization of a single huge composite value). Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-10:20260703-115000 |
…ON cast The Tuple/Map/Object -> JSON fallback serializes each row into an intermediate ColumnString and then parses that string back into a JSON column. Both loops ran uninterrupted for a whole block, so CAST(... AS JSON) still ignored KILL QUERY and max_execution_time one conversion over. Reuse the existing hook in the serialize loop (per-row throwIfQueryCancelled plus the shared CancellationCheckingWriteBuffer for a single huge value), and add the same per-row check to the generic from-String parse loop, which dominates the cost of this cast. Extend 04401 with a many-rows CAST(Map AS JSON) case that fails loudly without the parse-back check. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-10:20260703-142100 |
The new test failed CI two ways: a deterministic TOO_MANY_ROWS_OR_BYTES on arm_binary (the queries build results larger than CI's default max_result_bytes before FORMAT Null discards them), and a process-group Timeout in the flaky check (a multi-second wall-clock timing test run 50x under sanitizers). Add max_result_bytes = 0 to the queries, tag no-flaky-check (running a latency test 50x validates nothing and risks the timeout), and shrink the datasets so each run is a few seconds. The natural-time-relative assertion is unchanged; verified it still fails loudly against a build without the parse-back cancellation check. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Follow-up (b640b21): fixed two CI failures the new test 04401 caused on the previous head.
The natural-time-relative assertion is unchanged and still fails loudly against a build without the parse-back cancellation check. |
The per-case max_execution_time was ceil(0.45 * natural) seconds. For the single-value case (natural ~2.3s) that rounded a ~1s intent up to 2s, leaving only ~300ms between the limit and the natural time. Run-to-run variance then occasionally pushed an execution below the 2s limit, so no TIMEOUT_EXCEEDED fired and the two single-case lines went missing (flaky on the fast arm_binary runner). Use floor(natural * 0.35) seconds (min 1s) so the limit stays at ~0.35x the natural time with a wide margin, and widen the acceptance window upper bound to 0.7 * natural. Verified in both directions on a local debug build: with the fix all shapes stop at ~1s (8/8 harness runs pass, output unchanged); with the cancellation checks reverted all shapes run to their natural time and the test fails loudly. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Pushed 78466d5 to fix the remaining Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-14:20260703-161800 |
CI finish ledger — 78466d5Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
PR-caused gate: ZERO. This PR adds a cancellation check while serializing values to String; the failing test is an unrelated hash-join spilling flaky owned by the open fixing PR above. Session id: cron:our-pr-ci-monitor:20260703-210000 |
|
Agree with @Avogar. I find it even doubtful to check per row if the query was cancelled. If we really want to do this consistently across the code base, then hundreds, probably over one thousand SQL function implementations need to be changed. |
Per @Avogar and @rschu1ze review: checking cancellation per string reallocation via a CancellationCheckingWriteBuffer is overkill. Drop it and keep only the per-row QueryStatus::throwIfKilled() poll in the generic to-String and to-JSON serialize loops and the from-String parse loop. This covers the common many-rows-in-one-block hang, which is the shape the server-side fuzzer hit. The 04401 regression keeps the two multi-row shapes (both interrupted by the per-row check); the single-huge-value shape that needed the write buffer is dropped. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
@Avogar @rschu1ze agreed, simplified in fbe3e73. Dropped On rschu1ze's wider point: this does not try to make every serialization consistently interruptible, it only adds the per-row poll to the three generic-serialization loops in The 04401 regression is trimmed accordingly: the two remaining shapes ( |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-0:20260707-160200 |
| /// checkTimeLimit() honors KILL QUERY and max_execution_time in both timeout overflow modes; it returns | ||
| /// false (instead of throwing) for `break`, which we turn into a hard stop since a half-converted value | ||
| /// is not a useful partial result. Mirrors FunctionBaseXXConversion. | ||
| if (query_status && !query_status->checkTimeLimit()) |
There was a problem hiding this comment.
timeout_overflow_mode = 'break' is documented to return a partial result, but this helper turns the soft-timeout false from checkTimeLimit() into a thrown TIMEOUT_EXCEEDED. That "throw on false" pattern is fine in places like arrayFold / FunctionBaseXXConversion, where there is no meaningful partial value, but here the loop already has a prefix of fully converted rows.
In other words, after the simplification to row-level polling only, the break behavior for these conversions is no longer obviously "return the partial result" so much as "let the pipeline absorb an exception and drop the current block". 04401 cannot distinguish those outcomes because it runs under FORMAT Null and only checks exit status / duration. Please either preserve the soft-break semantics for these row-wise loops, or add a non-Null regression that proves the observable break result is still acceptable.
CI finish ledger — fbe3e73CI is complete (Finish Workflow passed; only the private "CH Inc sync" check remains, which does not run for fork PRs). Every failure below has an owner (a fixing PR or a full-effort fix task). None are caused by this PR's diff (this PR only touches
Session id: cron:our-pr-ci-monitor:20260707-220000 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 34/35 (97.14%) · Uncovered code |
CI finish ledger — f6a1ad2Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The The integration cascade is a trunk defect in the Session id: cron:our-pr-ci-monitor:20260729-060000 |
|
I don't think we want this implementation. Because as Robert said, If we really want to do this check per row, we would need to change quite a lot of code across the database for consistency. |
|
Understood, withdrawn. I will not reopen this or push a variant. The signature that motivated it (a cancelled query parked in |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
toStringandCAST(... AS String)of a composite value (Dynamic,Array,JSON, ...) now check for query cancellation while serializing, soKILL QUERYandmax_execution_timeare honored during the conversion instead of only between pipeline blocks.Description
toString/CAST(... AS String)of a composite value goes throughConvertImplGenericToString::execute, which loops over all rows in the current block callingserializeTextper row. The query's time and cancellation limits are only checked between pipeline blocks (inPipelineExecutor), so a single large block kept a thread serializing for a long time afterKILL QUERYormax_execution_time, with no way to interrupt it.The server-side AST fuzzer (serverfuzz stress test) repeatedly hit this and tripped
Hung check failed, possible deadlock found. The processlist showed a cancelled query (is_cancelled = 1) still running for hundreds of seconds, with the worker thread stuck in:Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108788&sha=a4eed43b831dbeebcc63925d98d9e95f1ef36d89&name_0=PR&name_1=Stress%20test%20%28amd_asan_ubsan%29
Fix: the per-row loop now calls
QueryStatus::throwIfKilled()(a cheap atomic load that throwsQUERY_WAS_CANCELLED/TIMEOUT_EXCEEDEDonce the query is cancelled;max_execution_timeflips the flag viaCancellationChecker). This mirrors the existing pattern for the base58 conversion (FunctionBaseXXConversion). TheQueryStatusis taken from the query context inFunctionConvertSettingsand is null for the context-lesscastColumn()path, where there is nothing to cancel.Verified locally on a Debug build:
KILL QUERY ... SYNCon a single-blocktoString(<Dynamic>)dropped from ~8.7s (blocked until the loop finished) to ~0.2s. The regression test04401_to_string_dynamic_serialize_honors_cancellationfails without the fix (KILLblocks for the full serialization time) and passes with it.This is a runtime value-serialization fix and is independent of #108863, which caps parser/AST-depth settings in the CI fuzzer/stress harness and does not bound this path.