Repository navigation
Conversation
IMergingTransformBase::prepare reads every source to the end when always_read_till_end is set (from exact_rows_before_limit), so that rows_before_limit_at_least stays exact. That drain returned NeedData unconditionally after touching the first unfinished input. InputPort::isFinished() is masked while a pushed chunk is unconsumed: a producer may push its last chunk and finish within one prepare, and until that chunk is pulled the input reports not-finished. The drain therefore picked such an input, pulled the chunk - after which the input really is finished - and then waited on it. Its producer was already Finished and emitted no further event, so no edge was queued for the merge and nothing rescheduled it. The merge stayed parked in NeedData while a later input remained back-pressured. In a release build the query hangs; in debug and sanitizer builds PipelineExecutor::finalizeExecution throws "Pipeline stuck". Re-check the input after the pull and continue to the next one, returning NeedData only while some producer can still deliver. LimitTransform, the only other always_read_till_end drain, already does this. When every input turns out finished, control falls through into the existing completion path rather than duplicating it. Reachable on master without any patch through a Distributed table read via remote(): 17 "Pipeline stuck" rows across 15 distinct pull requests since 2026-07-22, on AST fuzzer and BuzzHouse in six build flavours. The added case in 03408_limit_by_rows_before_limit_dist aborts on master and passes with this change, 50/50 randomized runs clean. Reported rows_before_limit_at_least is byte-identical before and after across 25 query and max_threads combinations, so the drain's purpose is preserved. All ten IMergingTransformBase subclasses share this prepare, but nine hardcode always_read_till_end = false, so only MergingSortedTransform reaches the changed loop. Closes: ClickHouse#114723
The case added for the always_read_till_end drain hang asserted rows_before_limit_at_least without pinning prefer_localhost_replica, which tests/clickhouse-test randomizes 0/1 per run. The setting selects the local-vs-remote branch for a local shard in SelectStreamFactory, which changes how many legs the rows_before_limit counter observes: 33 with a local shard, 44 without. The case was therefore nondeterministic under CI settings randomization. Pin prefer_localhost_replica = 1 in the query's own SETTINGS clause and set the reference to that topology's value. A query-level SETTINGS beats runner injection, so this pins one setting rather than disabling randomization for the whole file, and the four pre-existing cases keep their current topology and values. The value 1 is pinned rather than 0 because 0 does not reproduce the hang: on the pre-fix build the pinned query passes 20/20 with prefer_localhost_replica = 0 and dies with 2 Pipeline stuck lines with = 1. Pinning 0 would have shipped a regression test that cannot fail.
Internal second-model review (2 rounds, all findings adjudicated)An independent model reviewed this change cold in two rounds, plus my own review of the Round 1: one real defect, fixed ❌ The regression test was nondeterministic (fixed in
The pin is verified live in both directions: with the runner injecting Round 2: clean
Also verified against the code
|
|
Workflow [PR], commit [6293056] Summary: ❌
AI ReviewSummaryThis PR fixes Final Verdict✅ No blocking issues found in the current patch. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 8/8 (100.00%) · Uncovered code |
Pre-PR validation gate (a-i)
Validated on a Debug build. A TSan arm was not run locally; CI covers the sanitizer flavours. |
|
cc @yariks5s @novikd, could you review this? The |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units7 translation units recompiled, 6 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - 6293056Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Not caused by this PR. The hung query is a fuzzer-widened Session id: cron:our-pr-ci-monitor:20260824-113000 |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a hang in a sorted merge when
exact_rows_before_limitis enabled. A query withLIMITover sorted remote streams could stop making progress after the merge reached its limit, because the merge waited for an input that had already finished. In debug and sanitizer builds this surfaced as aPipeline stucklogical error instead.Description
Closes: #114723
IMergingTransformBase::preparereads every source to the end whenalways_read_till_endis set(from
exact_rows_before_limit), sorows_before_limit_at_leaststays exact. That drain returnedNeedDataunconditionally after touching the first unfinished input.InputPort::isFinished()is masked by a buffered chunk: a producer may push its last chunk andfinish within one
prepare, and until that chunk is consumed the input reports not-finished. Thedrain therefore picked such an input, pulled the chunk (after which the input really is finished)
and then waited on it. Its producer was already
Finishedand emitted no further event, so nothingrescheduled the merge. It stayed parked in
NeedDatawhile a later input remained back-pressured:in a release build the query hangs; in debug and sanitizer builds
finalizeExecutionthrowsPipeline stuck.The fix re-checks the input after the pull and continues to the next one, returning
NeedDataonlywhile some producer can still deliver.
LimitTransform, the only otheralways_read_till_enddrain, already does this. When every input turns out finished, control falls through into the
existing completion path.
Reachable on unpatched master via a
Distributedtable read throughremote(): 17Pipeline stuckrows across 15 distinct pull requests since 2026-07-22, on
AST fuzzerandBuzzHousein thedebug, ASan+UBSan, MSan and TSan builds.
Validation: the added case in
03408_limit_by_rows_before_limit_distfails on master and passeswith the fix (50/50 randomized runs clean). The drain's purpose is preserved: reported
rows_before_limit_at_leastis byte-identical before and after across 25 query/max_threadscombinations. All 13
IMergingTransformBasesubclasses share thisprepare, but 12 hardcodealways_read_till_end = false, so onlyMergingSortedTransformreaches the changed loop.Not addressed here: the exact
rows_before_limit_at_leastcount for plan-based parallel replicas,which #114723 also asks for. That needs the per-replica sort to become unbounded
(
applyParallelReplicas.cppcarries aFIXMEfor it) and was not re-tested against this change.Workflow [PR]
Sync PR [sync-upstream/pr/116051]
Workflow [PR]
Sync PR [sync-upstream/pr/116051]
Workflow [PR]
Sync PR [sync-upstream/pr/116051]