Repository navigation
Fix Port is already connected in LazyUnorderedReadFromMergeTreeSource::expandPipeline - #103230
Conversation
Pre-PR validation gateSession:
|
|
cc @KochetovNicolai @CurtizJ @alexey-milovidov — could you review this? It fixes the |
|
Workflow [PR], commit [75bc72c] Summary: ❌
AI ReviewSummaryThis PR fixes a real correctness issue in lazy ClickHouse Rules
Final Verdict
|
|
@groeneai Rebase on the latest master. |
…::expandPipeline
`LazyUnorderedReadFromMergeTreeSource::expandPipeline` used to iterate over
every processor returned by its `buildReaders()` helper and call
`connect(processor->getOutputs().front(), new_input)` on each. That worked
only when `ReadFromMergeTree::initializePipeline` produced a pipe whose
processors were all independent sources.
In general, `initializePipeline` can add internal transforms (e.g. `Resize`,
`ConcatProcessor`, simple transforms for sampling/filtering/row-level
security), in which case some processors' first output is already connected
to the next internal step. `Pipe::detachProcessors` returns a flat list that
includes those internally-wired processors, so the old loop would trip over
those already-connected ports with:
Logical error: 'Port is already connected, (header: [...])'.
This reproduced in master `Stress test (arm_release)` on commit
`55a7ff843d71c95398f5b4defe5191a6f976df74` (STID 0996-3f3c) and is
reproducible locally against 26.4.1.1 with a plain
`SELECT count() FROM t FINAL WHERE category = 1`
using the lazy FINAL optimization: the server crashes within a few runs as
`max_threads` varies, because `initializePipeline` inserts a `Resize` when
the pool has more output ports than `output_streams_limit`.
Fix by matching the pattern already used by the sibling
`LazyReadReplacingFinalSource` (added in the same PR ClickHouse#101647): collect the
pipe's terminal output ports via `Pipe::getOutputPort(i)` before detaching
processors, then connect only those real outputs to the source's new input
ports.
Added regression test `04105_lazy_final_unordered_expand_pipeline` that
deterministically reproduces the crash on the unfixed binary and passes
with the fix (verified 50/50 with and without randomized settings).
Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=55a7ff843d71c95398f5b4defe5191a6f976df74&name_0=MasterCI&name_1=Stress%20test%20%28arm_release%29
Co-Authored-By: Claude Opus 4.7 <[email protected]>
2c0033e to
73402d0
Compare
|
@nikitamikhaylov @pufit Rebased on latest master at
CI is re-running on the new HEAD. Apologies for the multi-day delay — the previous rebase session died between local rebuild and force-push. Session: cron:clickhouse-ci-task-worker:20260424-021500 |
CI Status after rebase (73402d0)141 PASS / 16 SKIPPED / 4 PENDING / 1 FAIL (known chronic) ✅ All 11 stress tests GREENIncluding ❌ 1 failure —
|
|
cc @alexey-milovidov — escalating per the 24h threshold after my re-ping at 2026-04-24 05:25 UTC went unanswered. This PR is ready for merge. It has been blocking on reviewer response since the rebase ~27h ago. Status on rebased HEAD
Why this needs to land:
Bug summary: Fix: Save Could you re-approve on the rebased HEAD or hit merge if happy? Happy to address any further feedback. Session: |
Second escalation — 24h after first escalation, no review activityThe 24h threshold from my first escalation (2026-04-25 05:27 UTC) has now been reached without any reviewer response. The PR remains in MERGEABLE / BLOCKED state with no new activity since my last comment. Why I'm pinging the two of you (not @alexey-milovidov again)
I'm deliberately NOT re-pinging @alexey-milovidov — he saw yesterday's escalation while triaging a sibling lazy-materialization fix (#101144, merged 2026-04-25 12:52 UTC), so further pinging from me would just be noise. Trunk impact since first escalation (2026-04-25 05:27 UTC → 2026-04-26 05:15 UTC)
Last master hit: 2026-04-25 15:57 UTC ( Every day the fix doesn't merge, the trunk bug surfaces in another ~5–10 unrelated PR runs and developers waste time re-running CI or triaging the failure. PR state recap (HEAD
|
The test deliberately provokes logical errors via concurrent ALTER and INSERT. Re-running it many times under sanitizers blows the 180s per-test budget (`amd_asan_ubsan` flaky check) and reliably crashes debug builds (`amd_msan` flaky check), which is the bug this test documents but is not the right place for the flaky check to fail. The unrelated `Stress test (arm_debug)` "Port is already connected" in `LazyUnorderedReadFromMergeTreeSource` failure is being addressed by PR #103230. CI: #80416 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
@groeneai, please fix the Upgrade check (amd_release) and send a separate PR with the fix. If there is already an existing PR with the fix, link it here. After that, update the branch in this PR. |
…expand-pipeline-double-connect
|
@alexey-milovidov done — both directives addressed: 1. Upgrade check (amd_release) fix: The The relevant suppression in -e "Unknown tokenizer: 'unicode_word'" \plus a comment explaining the rename context. Pattern is narrowed to the exact legacy name so genuinely unsupported tokenizer names are not masked. 2. Branch updated: Merged
CI will rerun on the new HEAD. Awaiting your re-approval / merge. cc @KochetovNicolai @CurtizJ — KochetovNicolai's prior APPROVED on the pre-rebase commit needs refresh. |
|
@groeneai, function_prop_fuzzer has failed. If it is fixed by an existing PR, link it to this issue and update the branch. If not, send a separate PR with the fix and update the branch. |
|
@alexey-milovidov —
30+ unrelated PRs over the last 14 days hit this exact UBSAN line range plus 3 master hits. Once either lands and I re-merge master into this branch, I will re-merge master and force-push as soon as either #103717 or #102890 is merged. cc @CurtizJ @KochetovNicolai — could one of you re-approve the rebased HEAD Tracking task: |
|
@groeneai, ok, as we confirmed that the function_prop_fuzzer will be fixed, could you please update the branch in this PR, so we will have a chance to merge it? |
…expand-pipeline-double-connect
|
@alexey-milovidov branch updated with master HEAD Diff vs master is minimal — the lazy-unordered fix surface is
cc @KochetovNicolai @CurtizJ — could you re-approve the rebased+master-merged HEAD |
LLVM Coverage Report
Changed lines: 100.00% (17/17) · Uncovered code |
|
Friendly re-ping per @alexey-milovidov's request on #103917 — could either of you re-approve so we can merge? @KochetovNicolai approved 2026-04-21 (review dismissed by 2026-04-24 rebase). Branch updated with master 2026-04-30 (HEAD This has been blocking ~30+ unrelated PRs in the last week (STID 0996-3f42 / 327d / 3702 family — same root cause, same fix). |
Cherry pick #103230 to 26.4: Fix Port is already connected in LazyUnorderedReadFromMergeTreeSource::expandPipeline
…redReadFromMergeTreeSource::expandPipeline
Backport #103230 to 26.4: Fix Port is already connected in LazyUnorderedReadFromMergeTreeSource::expandPipeline
Motivation
Master
Stress test (arm_release)fails on commit55a7ff843d71c95398f5b4defe5191a6f976df74with:Stack trace:
Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=55a7ff843d71c95398f5b4defe5191a6f976df74&name_0=MasterCI&name_1=Stress%20test%20%28arm_release%29
The failure was introduced by #101647, which added
LazyUnorderedReadFromMergeTreeSourceas the lazy FINAL branch forReplacingMergeTree.Root cause
LazyUnorderedReadFromMergeTreeSource::expandPipelineiterated over the list of processors returned bybuildReaders()and calledconnect(processor->getOutputs().front(), new_input)on each one:buildReaders()forwarded toReadFromMergeTree::initializePipeline, which in general can add internal transforms (Resizewhenoutput_streams_limitis set,ConcatProcessorforInOrder, simple transforms for sampling/filtering/row policy, etc.).Pipe::detachProcessorsreturns a flat list that includes those internally-wired processors, so the loop eventually tripped over a processor whose first output was already connected to the next internal step, producing thePort is already connectedlogical error.The sibling source in the same PR,
LazyReadReplacingFinalSource, already uses the correct pattern: it storespipe.getOutputPort(0)before callingPipe::detachProcessorsand then connects only that saved terminal port inexpandPipeline.Fix
Return the
Pipefrom the helper, snapshotpipe.getOutputPort(i)fori in [0, numOutputPorts()), then detach processors and connect only those terminal ports to the source's new inputs. This is the same contractPipedocuments: "All other ports are connected, all connections are inside processors set" — onlyoutput_portsare guaranteed unconnected.No change to
LazyReadFromMergeTreeSource(the ordered sibling): it buildsMergeTreeSourceprocessors directly without going throughReadFromMergeTree::initializePipeline, so its pipe has no internal transforms and the old pattern is safe there.Reproduction
Deterministic locally on
amd_debugagainst the schema from03991_lazy_final_analysis_logging:With the fix, the loop runs to completion. Regression test
04105_lazy_final_unordered_expand_pipelinecaptures the same scenario and was validated in both directions:tests/clickhouse-test --no-random-settings --no-random-merge-tree-settings --test-runs 10 04105_lazy_final_unordered_expand_pipelinecrashes the server with the exact samePort is already connected, (header: [category UInt8 ...])logical error.03988..04095lazy-final tests continue to pass.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
Logical error: 'Port is already connected'exception during pipeline expansion in the lazyFINALpath forReplacingMergeTree. The bug affected queries withquery_plan_optimize_lazy_final = 1whenReadFromMergeTree::initializePipelineinserted internal transforms (e.g. aResize) that wired the sub-pipeline's processors together, causingLazyUnorderedReadFromMergeTreeSource::expandPipelineto try to connect output ports that were already connected.Documentation entry for user-facing changes
Version info
26.4.5.117