Skip to content

Fix pure-virtual call in printPipeline for a dangling output peer - #110955

Merged
alexey-milovidov merged 10 commits into
ClickHouse:masterfrom
groeneai:fix-printpipeline-dangling-output-peer
Aug 1, 2026
Merged

alexey-milovidov merged 10 commits into
ClickHouse:masterfrom
groeneai:fix-printpipeline-dangling-output-peer

Conversation

@groeneai

@groeneai groeneai commented Jul 18, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Description

Fixes the pure-virtual abort in printPipeline/dumpPipeline reported in #110834 (found by the
targeted AST fuzzer, AST fuzzer (amd_debug, targeted)).

printPipeline walked each processor's output ports to the peer processor via
port.getInputPort().getProcessor(). A Port stays isConnected() (its shared State is
ref-counted) and keeps the raw peer IProcessor* even after the peer processor is destroyed. When
a streaming query's pipeline is expanded/torn down, a downstream processor can be removed and freed
while a survivor still references it through a port. The debug-only exception dump
(PipelineExecutor::execute -> dumpPipeline -> printPipeline) then dereferenced that freed
peer: the "outputs not in processors" loop called getUniqID() -> pure-virtual getName()
(the reported __cxa_pure_virtual abort), and the edge loop read getInputPort().getProcessor()
(heap-use-after-free under ASAN). Release builds do not call dumpPipeline, so they are unaffected.

Fix: printPipeline no longer dereferences a processor reachable only through a port. The
out-of-collection node-label loop is removed, and edges are now matched between the passed
processors through the shared port-connection identity, so no peer processor is touched. Output for
well-formed pipelines is unchanged.

Added a unit test that reproduces the crash (a survivor whose output port points at a destroyed
peer) and asserts edges are still rendered for a well-formed pipeline.

Version info

  • Merged into: 26.8.1.619 (included in 26.8 and later)

…dangling output peer

printPipeline followed each processor's output port to the peer processor via
getInputPort().getProcessor(). A port stays connected (its shared State is
ref-counted) and keeps the raw peer pointer even after the peer processor is
destroyed, so during streaming-query pipeline teardown the debug-only exception
dump dereferenced a freed peer: the node-label loop virtual-dispatched
getUniqID() -> pure-virtual getName() (SIGABRT), and the edge loop read the freed
peer (heap-use-after-free under ASAN).

printPipeline no longer dereferences a processor reachable only through a port:
the out-of-collection node-label loop is removed and edges are matched between the
passed processors through the shared port-connection identity. Output for
well-formed pipelines is unchanged.

Related: ClickHouse#110834

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. gtest PrintPipeline.DoesNotDereferenceDanglingOutputPeer: connect a survivor to a downstream peer, destroy the peer, then printPipeline({survivor}). Fails on demand every run.
b Root cause explained? Yes. printPipeline follows each output port to its peer via getInputPort().getProcessor(). A Port stays isConnected() (shared State is ref-counted) and keeps the raw peer IProcessor* after the peer is destroyed. During streaming-query pipeline teardown a downstream processor is removed/freed while a survivor still references it through a port; the debug-only exception dump then dereferences the freed peer.
c Fix matches root cause? Yes. printPipeline no longer dereferences a peer reachable only through a port: the out-of-collection node-label loop is removed and edges are matched between the passed processors via the shared port-connection identity. Targets the exact mechanism in (b).
d Test intent preserved / new tests added? Yes. New gtest (2 cases): the crash reproducer + DrawsEdgeBetweenProcessorsInSet asserting a well-formed pipeline still renders node + edge. No existing test weakened; all 6 existing Processors.* gtests still pass.
e Both directions demonstrated? Yes. Without fix: debug → Pure virtual function called! (exit 134), ASAN → heap-use-after-free (exit 134). With fix: debug + ASAN pass (exit 0). Build ID changed 4a261b33→1276bc52.
f Fix is general across code paths? Yes. Removing only the node-label loop was verified INCOMPLETE — the edge loop is a second manifestation of the same root cause (ASAN heap-UAF). Both loops fixed. printPipelineCompact shares the shape but is only used on well-formed pipelines (all peers in-set), out of scope for this teardown crash.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (diagnostics memory-safety fix, not a data-type-dependent code bug). The fix is input-agnostic; both degenerate (dangling peer) and normal (well-formed) shapes are covered by the test.
h Backward compatible? (maintainer-approved exception only) Yes. No setting / on-disk / wire / replication / default changed. Only a debug diagnostics function and a header-only opaque accessor. printPipeline output for well-formed pipelines is unchanged (verified via EXPLAIN PIPELINE).
i Invariants and contracts preserved? Yes. Port::getConnectionId() exposes only opaque pointer identity of the shared state (never dereferenced, does not expose the protected State type), so no Port invariant is touched. printPipeline's contract is upheld: for a well-formed pipeline every output port matches exactly one owned input port, so all edges are still drawn; only edges to removed/dangling peers are dropped (strictly safer).

Session id: cron:clickhouse-author-slot-2:20260718-194700

@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review — adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 2 findings; bounded: 1 full pass + 1 fix round + 1 delta recheck).

# Sev Finding Verdict Evidence / action
1 ⚠️ Removing the "outputs not in processors" loop drops rendering of a live downstream peer omitted from the set DISAGREE No real caller passes a set that omits a live connected peer. Pipe documents the invariant "all connections are inside processors set", and ExecutingGraph::addEdge throws if a connected peer is not a graph node — so for QueryPipeline/Pipe/ExecutingGraph::getProcessors callers every connected peer is in-set and the removed loop was already a no-op (inserted==false→continue). Verified: EXPLAIN PIPELINE graph=1, compact=0 renders all nodes + edges identically. The only out-of-set peer arises from removeNode during teardown and is destroyed → cannot be rendered safely (that is the crash). No live-omitted-peer case exists to preserve.
2 ⚠️ .meta.json (task-workspace metadata) included AGREE Not part of the fix. It is untracked workspace bookkeeping, was never staged (commit built file-by-file, never git add -A), and git show --stat HEAD confirms the commit contains only the 3 intended source files. Not pushed.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding. Findings on hunks unchanged by the fix round are auto-dropped.

Session id: cron:clickhouse-author-slot-2:20260718-194700

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @yariks5s @vdimir — could you review this? It fixes the pure-virtual abort in printPipeline/dumpPipeline from #110834: the diagnostics walk dereferenced a downstream processor reachable only through a port after that processor was destroyed during pipeline teardown (pure-virtual call in debug, heap-use-after-free under ASAN). The fix stops dereferencing out-of-set peers and matches edges through the shared port-connection identity instead.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jul 18, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [73d641a]

Summary: ✅


AI Review

Summary

This PR rewires printPipeline to match edges by shared Port state instead of dereferencing the peer processor, which looks like the right fix for the dangling-output dump path and keeps well-formed pipeline output intact. The remaining problem is that the same dangling-peer walk still exists in processor-profile collection on the successful-query finish path, so the underlying use-after-free is still reachable in release builds.

Findings

❌ Blockers

  • [src/Processors/IProcessor.cpp:166-171] IProcessor::getProcessorsProfileLogInfo still does port.getInputPort().getProcessor() on the already-pruned Processors list collected from src/Interpreters/executeQuery.cpp:650-655. ExecutingGraph::removeNode erases finished processors from that shared list before logging, so a surviving output can still be isConnected() while its downstream owner has already been destroyed. This means the same dangling-peer dereference the PR removed from printPipeline is still reachable on successful query completion through getProcessorsProfileLogInfo. Suggested fix: collect parent_ids against the whole passed Processors set via Port::getConnectionId() (or otherwise skip peers whose owning input processor is absent from the set) instead of dereferencing the raw peer processor.
Final Verdict

printPipeline itself looks fixed, but I would not clear the PR while the adjacent release-reachable getProcessorsProfileLogInfo dereference is still present.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 18, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Jul 19, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — b11a3d8

Every failure below has an owner (a fixing PR). None are caused by this PR's diff (a debug/CI-only printPipeline.h + Port.h change plus a gtest; release builds never call dumpPipeline).

Check / test Reason Owner / fixing PR
Integration tests (amd_tsan, 3/6) + (arm_binary, distributed plan, 1/4) / test_replicated_database::test_replicated_table_structure_alter flaky (chronic trunk: 97 master hits/14d, 20+ unrelated PRs) #110030 (ours, open)
Stateless (amd_llvm_coverage, old analyzer, s3, DBReplicated, WasmEdge, parallel, 2/3) / Server died + Unknown error crash (chronic coverage SIGABRT: multiply Int256*Float64 partial-result type mismatch under concurrent EXCHANGE TABLES; 20 master hits/14d) #109747 (ours, open) + #110048 (external, open)
Mergeable Check / PR derivative — red only due to the above (resolves when the above land)

Session id: cron:our-pr-ci-monitor:20260719-063000

Comment thread src/Processors/Port.h
/// Lets diagnostics match an output port to its peer input port without dereferencing the
/// peer processor, whose lifetime is not guaranteed during pipeline teardown. Opaque on
/// purpose: only pointer identity is meaningful.
const void * getConnectionId() const { return state.get(); }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

printPipeline is safe after this change, but the same dangling-peer dereference is still present in processor-profile collection. ExecutingGraph::removeNode erases finished processors from the shared Processors list and delayed_destruction frees them before the post-execution logging passes run; after that, a surviving output port can still be isConnected() while output.getInputPort().getProcessor() is dangling.

We still call IProcessor::getProcessorsProfileLogInfo on that mutated list from finalizeQueryPipelineBeforeLogging, PreparedSets, and scalar-subquery logging, and that method still does the raw peer dereference. So this patch removes the UAF from printPipeline, but the same shape can still blow up on successful query completion / profile logging. Please switch the parent_ids walk to the same getConnectionId()-based lookup (or otherwise skip peers whose owning input processor is no longer present).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified: this finding is real. IProcessor::getProcessorsProfileLogInfo() (src/Processors/IProcessor.cpp:166-172) does the identical peer deref this PR removed from printPipeline: it walks outputs, checks isConnected(), then port.getInputPort().getProcessor(), and getProcessor() (Port.h:258) reads the peer input port's processor inside a possibly-freed peer. finalizeQueryPipelineBeforeLogging calls it at src/Interpreters/executeQuery.cpp:634, right beside the printPipeline call at :639, over the same getProcessors() list, and unlike dumpPipeline it is not #ifndef NDEBUG and not gated by log_processors_profiles, so it is release-reachable on normal query finish.

This PR stays scoped to the reported debug-only printPipeline/dumpPipeline crash (#110834) and is already approved. The release-reachable profile-log UAF is a distinct, higher-severity issue; folding it in would rebuild an approved PR around a broader change. I will fix it in a separate follow-up PR that switches the parent_ids walk to the same getConnectionId()-based lookup (skip peers whose owning input processor is not in the set). Tracked separately.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up opened: #111019. It moves the parent_ids walk into the free getProcessorsProfileLogInfo(const Processors &) and matches ports by getConnectionId() shared-state identity, so the peer processor is never dereferenced. Regression gtest reproduces the release heap-UAF under ASAN without the fix and passes with it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Status update on this thread: the follow-up #111019 was closed today by @yariks5s with CHANGES_REQUESTED. The objections there are about the design of the profile-log fix, not about its memory-safety claim — that getProcessorsProfileLogInfo would stop populating parent_ids, that it changes system.processors_profile_log semantics for peers absent from the supplied set, that it adds a hash-map allocation on every successful-query finish path even when processor-profile logging is disabled, and that matching by connection id works around the dangling pointer rather than fixing the port/processor lifetime. @yariks5s noted they will come back to it.

So the release-reachable dereference this thread points at is still real and now has no open PR behind it; it is waiting on a maintainer design call on how to fix it (connection-id lookup vs. fixing the lifetime so a connected port never outlives its peer). Recording that here so the thread is not read as "already handled elsewhere".

This PR stays scoped to the debug-only printPipeline/dumpPipeline path that @alexey-milovidov approved. Folding the profile-log change in here would import exactly the design question that is still open, into an approved and otherwise green PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracking issue opened for this finding so it is not lost now that #111019 is closed: #112320. It records the release-reachable path (logQueryFinish -> getProcessorsProfileLogInfo), the confirmation from this thread, and the design objections that closed #111019, so whoever picks it up starts from the open question rather than from the rejected patch.

This pull request stays scoped to the debug-only printPipeline / dumpPipeline fix that was approved here; folding the profile-log fix back in would re-import an unresolved design question into it.

@alexey-milovidov alexey-milovidov mentioned this pull request Jul 23, 2026
1 task done
@alexey-milovidov

alexey-milovidov commented Jul 26, 2026 •

Copy link
Copy Markdown
Member

@groeneai, investigate the failure: https://github.com/ClickHouse/ClickHouse/actions/runs/30141497100/job/89654934179 — Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel) fails with Server died and Logical error '!part.empty()' (STID: 5217-5b3d).

This is unrelated to this PR (the diff only touches printPipeline.h, Port.h and a new gtest, none of which is reachable from part handling). The same two failures, including the very same STID, occur on plain master in the exact same check: a query over play.clickhouse.com checks for the last 7 days with pull_request_number = 0 gives Server died 5/5 and Logical error '!part.empty()' (STID: 5217-5b3d) 2/2 in Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel), plus more occurrences in the old analyzer, DBReplicated coverage job and in several Stress test jobs.

I could not find an existing tracking issue for it. Please file one and provide a fix in a separate PR, or link the fix here if it is already in progress.

@groeneai

Copy link
Copy Markdown
Collaborator Author

@alexey-milovidov, the failure is tracked and the fix is in progress: issue #110518, fix PR #111689 (Closes #110518, open and mergeable). No new issue is needed.

Your search missed the issue because !part.empty() is not the real abort message. I pulled clickhouse-server.err.log.zst for that job (654672 lines) and it contains exactly one <Fatal> logical error:

09:39:33.491168 [ 7991 ] {a301a1bb-...} <Fatal> : Logical error: 'Got read request from replica 2 for unknown stream test_b4jmrhvq.`.inner_id.78fe071e-...`.'
...
12. src/Storages/MergeTree/ParallelReplicasReadingCoordinator.cpp:1295: DB::ParallelReplicasReadingCoordinator::handleRequest(DB::ParallelReadRequest)
13. src/QueryPipeline/RemoteQueryExecutor.cpp:869: DB::RemoteQueryExecutor::processMergeTreeReadTaskRequest(DB::ParallelReadRequest)

Signal 6, query SELECT count() FROM mv WHERE id = 999999999 from 04493_create_or_replace_materialized_view_populate_keeps_subscription_concurrent.sh. Server died and the NOT_FAILED tests in that job are collateral of this abort.

The only occurrence of part.empty anywhere in that log is an SQL comment:

-- (e.g. `__table1.`) used to abort the server with Logical error '!part.empty()'

from 04367_lambda_arg_backquoted_dot_no_logical_error.sql, echoed into the server log by executeQuery. FuzzerLogParser in ci/jobs/scripts/log_parser.py names a failure by running rg -o 'Logical error.*' over the whole server log and taking the first match, so it picked that comment while the STID and stack came from the genuine abort. #111708 fixes the reporter by anchoring the match to a real formatted <Fatal> record.

CIDB shows the same STID under both labels in the same check (7 days, pull_request_number = 0): Logical error '!part.empty()' (STID: 5217-5b3d) 2 hits and Logical error: Got read request from replica A for unknown stream B. (STID: 5217-5b3d) 1 hit. The sibling STID 5217-505b in the same job is the same bug and carries the honest label 20 times against 13 mislabelled ones.

On the cause: the query log entry for the aborting query has projections = ['test_b4jmrhvq..inner_id.78fe071e-...._exact_count_projection'], which is one of the four paths #111689 addresses. When a projection optimization fully replaces the initiator's ReadFromMergeTree with a ReadFromPreparedSource, initializePipeline() never runs, so the empty read set is never announced to the coordinator, and a follower that did not take the same short circuit requests a stream that was never registered.

The old analyzer, DBReplicated coverage job is a different bug that the same reporter defect mislabels identically: STID 2735-47bf, real message Arguments of 'multiply' have incorrect data types: 'n' of type 'Int256', '0.123' of type 'Float64' from 03915_exchange_tables_race, tracked in #110133 with #110048 and #109747 in flight.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 1a48aad

Every 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.

Check / test Reason Owner / fixing PR
Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel) / Server died + !part.empty() (STID 5217-5b3d) parallel-replicas unknown-stream abort, trunk bug #111689 (ours, open)

Fast test and Style check are green on this head.

Session id: cron:our-pr-ci-monitor:20260726-163000

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 169b823

Every 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 CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stress test (amd_asan_ubsan) / UndefinedBehaviorSanitizer: undefined behavior (STID 0250-3bba) sanitizer finding on trunk, NOT PR-caused. Verified from the job artifacts rather than the truncated report row: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /ClickHouse/src/Functions/toStartOfInterval.cpp:293:80 / signed integer overflow: -9223372036854775808 + -3600000000000 cannot be represented in type 'Int64', frames execute<DataTypeDateTime64, ..., IntervalKind::Kind(5)> -> dispatchForIntervalColumn (:211) -> dispatchForTimeColumn (:146) -> executeImpl (:109). Nothing in my diff touches date/time functions. a fix task is created (investigating at full effort - fixing-PR link to follow here)

This head is a plain merge of origin/master into the branch, with no source change of mine. The
previous ledger's parallel-replicas line (STID 5217-5b3d, owner #111689) did NOT recur here, and
neither did this PR's own subject signature STID 2273-2dbb. Mergeable Check and the PR rollup
are aggregates of the single Stress test line above.

PR-caused gate: ZERO.

Session id: cron:our-pr-ci-monitor:20260727-073000

@groeneai

Copy link
Copy Markdown
Collaborator Author

Discharging the finish-ledger line for the Stress test (amd_asan_ubsan) UBSan failure
(STID 0250-3bba, signed integer overflow at src/Functions/toStartOfInterval.cpp:293:80).

Fixing PR: #112045 (@ alexey-milovidov, open) adds a common::addOverflow check to the
origin + offset composition in the three-argument toStartOfInterval overload and throws
DECIMAL_OVERFLOW instead of wrapping. I verified it covers the site: that addition is the only
unguarded one left in the block, since the time_arg - origin subtraction a few lines above is
already checked on master.

Root cause, for the record: for the whole-second units the origin path passes the duration
time_arg - origin into DateLUTImpl time-point helpers, which re-anchor it at a local midnight,
so the returned offset is negative by the time zone's UTC offset; adding it to an origin near the
lower bound of Int64 overflows. Unrelated to this PR's diff.

Note for anyone matching this signature later: it is recorded under at least three different STID
buckets (0250-4a9f, 0250-3bba, 0250-45ad), each of which also buckets the already-fixed
DateLUTImpl.h:301 / :1148 sites, so match on the file and line rather than on the STID.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 92b763b

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (amd_tsan, parallel) / 04611_join_runtime_filters_index_analysis_skip_index randomized-settings flaky, NOT PR-caused. The runner's own diagnosis is conclusive: with the same randomized settings 13/13 runs fail, without randomization 15/15 pass, and minimization names the single culprit --join_runtime_filter_min_probe_rows 6507. Above that threshold the runtime filter is not built, so the assertions on filter effects read 0 0 instead of 1 1 / 1. Nothing in my diff (Port.h, printPipeline.h, one gtest) touches join runtime filters. #111691 (external, open) - it adds SET join_runtime_filter_min_probe_rows = 0 to this exact test file, which pins the culprit setting
Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel) / Logical error: 'Got read request from replica 2 for unknown stream <db>.\.inner_id.…`'` (STID 5217-5b3d) parallel-replicas coordinator asked for a stream the replica never announced, on an inner MV table; abortOnFailedAssertion under the coverage build. Not reachable from my diff. #111689 (mine, open)
Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel) / Server died same job, same event - the abort above is what killed the server. #111689 (mine, open)
Mergeable Check, PR aggregate roll-ups of the two job lines above. as above

This head is @alexey-milovidov's plain merge of origin/master into the branch (2026-07-27T20:52Z);
it carries no source change of mine, so the PR-caused gate is ZERO. Fast test, Fast test (arm_darwin),
Style check, Config Workflow, Finish Workflow and CH Inc sync are all green, and every
Stress / AST fuzzer job passed.

Cleared versus the 169b823007e0 ledger: the toStartOfInterval UBSan line (STID 0250-3bba, owner
#112045) did not recur, and this PR's own subject signature STID 2273-2dbb did not recur either.

Session id: cron:our-pr-ci-monitor:20260728-110000

out << " n" << current_proc_id << " -> n" << get_proc_id(next) << ";\n";
/// Only draw the edge if the peer input port belongs to a processor in this set.
auto it = input_connection_to_id.find(port.getConnectionId());
if (it == input_connection_to_id.end())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

printPipeline is also used on malformed-but-live processor sets in the PipelineExecutor constructor catch (PipelineExecutor.cpp:128-135), immediately after ExecutingGraph::addEdge throws because a connected peer is missing from processors (ExecutingGraph.cpp:77-86). In that path the peer is not dangling, so the removed unmatched-output rendering was the only place the appended DOT dump kept the missing node and edge. After this continue, the exception still gives only to->getName(), but the graph no longer shows which edge is broken, which becomes ambiguous once several processors share that name.

Can we keep a synthetic node and edge for unmatched getConnectionId() values (or otherwise preserve the missing-peer information in the appended pipeline dump) instead of dropping them entirely?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified the mechanism, and it is partly right, but the requested remedy is not implementable without reintroducing the crash.

Correct: PipelineExecutor.cpp:120-136 is a second caller of the branch I removed, it is not #ifndef NDEBUG, and in that path the peer really is live rather than dangling. ExecutingGraph's constructor adds every node before any edge (ExecutingGraph.cpp:30-36), so when addEdge throws at :77-86 the absent peer is a live processor that is merely outside the collection. And getUniqID is getName()_processor_index with a per-thread counter (IProcessor.h:139, IProcessor.cpp:29), so it does disambiguate same-named processors.

One correction: the exception is not limited to to->getName(). It reads "Processor {to} was found as {input|output} for processor {from}, but not found in list of processors", so both endpoints of the broken edge and its direction are already reported. What the removed loop added on top was the numeric suffix.

Why I cannot keep a synthetic node for unmatched getConnectionId() values: the connection id is safe as a key, because the shared Port::State outlives either side, but it carries no peer identity. Port::State (Port.h:55-152) has exactly one data member, std::atomic<Data *> data, holding a chunk, an exception and three flag bits; grepping its body for IProcessor, InputPort, OutputPort or processor returns nothing. The peer's name is reachable only through port.getInputPort().getProcessor() (Port.h:487, :250), which is precisely the dereference that aborts on a freed peer. So a synthetic node could only be an anonymous placeholder, and it would add nothing beyond what the exception message already prints.

It would also not be free elsewhere. printPipeline has nine callers, and only this one and QueryPipeline.cpp:84 are malformed-set paths. The rest pass well-formed sets, including executeQuery.cpp:651 on successful query finish, ProcessorsProfileLog.cpp:160, and user-facing EXPLAIN PIPELINE graph=1 (InterpreterExplainQuery.cpp:1130, :1148). Emitting placeholder nodes unconditionally would put phantom nodes into EXPLAIN output and into successful-query profile dumps whenever a set legitimately omits a peer.

The useful version of this lives one layer up rather than in the dump: ExecutingGraph::addEdge can print to->getUniqID() instead of to->getName(), which is safe there because the peer is alive and the line already dereferences it. That recovers the suffix for exactly the path you are describing, in one line, without any placeholder rendering. I have filed it as a separate follow-up rather than folding it in here, since it is a different file and a different concern, and this pull request is approved, green and deliberately scoped to the debug-only dump path.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The follow-up described above is now filed: #112745. It changes the ExecutingGraph::addEdge exception to name both endpoints of the broken edge via getUniqID instead of getName, which restores the numeric disambiguation for the malformed-graph path without any placeholder rendering in the dump.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 2b46255

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (arm_binary, parallel) / 04357_distributed_alias_same_expression result differs with reference (un-merged GROUP BY partials over a Distributed table); the runner's own diagnosis reports 16 of 83 reruns failing a fix task is moved to pending (investigating at full effort, fixing-PR link to follow on this PR)

All 174 check-runs on this head are completed and the praktika Finish Workflow aggregator
has run; this is the only failure.

It is not caused by this diff, which touches src/QueryPipeline/printPipeline.h and the
pipeline-dump path. 04357 is a distributed duplicate-ALIAS aggregation test whose failure mode
is a 300 300 2 versus 300 300 1 result diff, independent of pipeline dumping. Breadth over
30 days is wide and reaches trunk: 28 or more distinct pull requests plus master rows, across
Stateless tests (arm_binary, parallel), (amd_debug, parallel) and (amd_asan_ubsan, distributed plan, parallel). No fixing PR exists for this signature yet, so it gets a
full-effort fix task rather than a link.

Session id: cron:our-pr-ci-monitor:20260730-180000

@groeneai

Copy link
Copy Markdown
Collaborator Author

Correction to the owner column of my CI finish ledger for 2b4625555427b71e4a2a2236a836485ea65806d8 above.

The Stateless tests (arm_binary, parallel) / 04357_distributed_alias_same_expression line has a fixing PR, so it should have been linked instead of left to a fix task: #108855 (mine, open), "Fix wrong results for duplicate-ALIAS GROUP BY on a Distributed table under two-level aggregation". It carries the engine fix and updates 04357_distributed_alias_same_expression.sql and its reference file directly.

The failing statement is SELECT length(a1) AS l, length(a2) AS m, count() AS c FROM dist_longlit GROUP BY a1, a2 ORDER BY l, where a1 and a2 are duplicate ALIAS columns expanding to the same expression. The shard collapses those two GROUP BY keys into one before computing two-level bucket numbers, while the initiator still buckets by both, so equal groups from different shards land in different buckets and never merge. That produces exactly the observed 300 300 2 becoming 300 300 1 twice.

A 14-day settings fingerprint over the non-flaky-check rows, with the host-OOM rows excluded, shows group_by_two_level_threshold_bytes=1 in 48 of 48 and prefer_localhost_replica=0 in 48 of 48, while distributed_aggregation_memory_efficient splits 29 to 19. The first forces the two-level path and the second forces a real remote read per shard, which are precisely that code path's preconditions, so the failure is tied to it rather than to test-local non-determinism.

Nothing changes for this PR: the failure is still not caused by its diff, and nothing was pushed.

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog and removed pr-ci labels Jul 31, 2026
@groeneai

groeneai commented Aug 1, 2026 •

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 9354e30

Every 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 CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (arm_asan_ubsan, targeted) / 04611_join_runtime_filters_index_analysis_skip_index randomized-settings flaky (join_runtime_filter_min_probe_rows) #111691 (external, merged 2026-07-31T20:56Z): this build predates it, so the pin arrives with the next master merge on this branch
Stress test (amd_msan) / Logical error Cannot capture column 2 ... got Nullable(UInt64), but UInt64 is expected (STID 3293-46fa) trunk bug in FunctionCapture under join_use_nulls #111993 (ours, open)
Integration tests (arm_binary, distributed plan, 1/4) / 57 test_storage_rabbitmq cases one event: the RabbitMQ container never started, so rabbitmq_cluster setup failed for the whole module a fix task is created (investigating at full effort, fixing PR link to follow on this PR)
Fast test (arm_darwin) job-level ERROR, run wedges with no test row (residual after merged #112267, which is already on this branch) a fix task is moved to pending (investigating at full effort, fixing PR link to follow on this PR)

Session id: cron:our-pr-ci-monitor:20260801-003000

@clickhouse-gh

clickhouse-gh Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.50% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.70% 78.70% +0.00%

Changed lines: Changed C/C++ lines covered: 50/52 (96.15%) · Uncovered code

Full report · Diff report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 1, 2026
Merged via the queue into ClickHouse:master with commit 707bb67 Aug 1, 2026
179 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 1, 2026
@groeneai

groeneai commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

Following up on the Integration tests (arm_binary, distributed plan, 1/4) line of the CI finish ledger for 9354e30b431e990cf3140d1b11a5e29b641aa49e. That job failed because the RabbitMQ container never started, which fails every test in test_storage_rabbitmq through its module-scoped fixture, so the 57 rows are one event.

I opened #113610 for it, but only for the cost of that failure, not its cause: wait_rabbitmq_to_start re-collected its diagnostics until a second 120s deadline expired before raising, and it now collects once. The container-start failure itself is still unexplained. The broker never boots, the container never leaves health: starting, and it emits no output, so I have nothing to report on the cause yet.

pull Bot pushed a commit to AnotherGenZ/ClickHouse that referenced this pull request Aug 9, 2026
When `ExecutingGraph::addEdge` finds a connected peer that is missing from
the list of processors, the thrown `LOGICAL_ERROR` named both endpoints of
the broken edge via `getName`, which is ambiguous when several processors
share a name. Use `getUniqID` (the name plus the per-thread processor
index) for both endpoints instead; both processors are alive at this
point, so the call is safe. This recovers the disambiguation previously
provided by the out-of-set node rendering that was removed from
`printPipeline` in ClickHouse#110955.

Related: ClickHouse#110955

Co-Authored-By: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants