Skip to content

Fix logical error in ExecutingGraph after a pipeline expansion failed halfway - #121502

Merged
alexey-milovidov merged 1 commit into
masterfrom
fix/executing-graph-failed-expansion
Sep 22, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
fix/executing-graph-failed-expansion

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Related: #99495

A processor that returns Status::UpdatePipeline connects its ports to the new processors before ExecutingGraph::updatePipeline records them, and recording them allocates, so it can throw on the memory limit halfway. The graph is then inconsistent with the ports: a live node is connected to a processor that never became a node. The exception cancels the executor, but another thread that is already inside updateNode takes the nodes_mutex write lock next, expands its own node, walks every node in addEdges and hits that connection with

Logical error: 'Processor ConvertingAggregatedToChunksWithMergingSource_64 was found as input for processor ConvertingAggregatedToChunksTransform_63, but not found in list of processors'

which aborts the server in debug and sanitizer builds. Seen in the stress test (arm_msan) with memory_tracker_fault_probability on a GROUP BY GROUPING SETS query, where several AggregatingTransforms expand the pipeline concurrently: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=99495&sha=8e4aa21ffdd0b8611618c8e742e10b00af776955&name_0=PR&name_1=Stress%20test%20%28arm_msan%29 (that PR does not touch the executor; the failure appears only once in 21 days of CI history, so it is rare).

updatePipeline now marks the graph when it throws while recording an expansion and keeps the new processors alive, since ports of live nodes point at them; a later expansion sees the mark and returns Cancelled instead of walking the inconsistent graph. The exception itself still propagates and cancels the query as before.

The failure is injected through the new failpoint executing_graph_add_node_fail, and the gtest drives ExecutingGraph directly, because the window between the two expansions cannot be hit reliably through the executor. Without the guard the test reproduces the logical error above (verified with a control build). A server-level check with the failpoint enabled on the GROUPING SETS query from the report fails cleanly with MEMORY_LIMIT_EXCEEDED on every run and logs no logical error.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix a logical error (Processor ... was found as input for processor ..., but not found in list of processors) that could abort the server when a pipeline expansion, such as the merge stage of a GROUP BY, failed on the memory limit while another expansion of the same query was in flight.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/121502]

Version info

  • Merged into: 26.10.1.455-master (included in 26.10 and later)

…ed halfway

A processor that returns `Status::UpdatePipeline` connects its ports to the
new processors before `ExecutingGraph::updatePipeline` records them, and
recording them allocates (`processors->push_back`, `nodes.emplace_back`,
`processors_map.emplace`, the edge lists), so it can throw on the memory
limit halfway. The graph is then inconsistent with the ports: a live node
is connected to a processor that never became a node. The exception cancels
the executor, but another thread that is already inside `updateNode` takes
the `nodes_mutex` write lock next, expands its own node, walks every node in
`addEdges` and hits that connection:

    Logical error: 'Processor ConvertingAggregatedToChunksWithMergingSource_64
    was found as input for processor ConvertingAggregatedToChunksTransform_63,
    but not found in list of processors'

which aborts the server in debug and sanitizer builds. Seen in the stress
test (arm_msan) with `memory_tracker_fault_probability` on a
`GROUP BY GROUPING SETS` query, where several `AggregatingTransform`s expand
the pipeline concurrently:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=99495&sha=8e4aa21ffdd0b8611618c8e742e10b00af776955&name_0=PR&name_1=Stress%20test%20%28arm_msan%29
(PR #99495, which does not touch
the executor).

`updatePipeline` now marks the graph when it throws while recording an
expansion and keeps the new processors alive, since ports of live nodes point
at them; a later expansion sees the mark and returns `Cancelled` instead of
walking the inconsistent graph. The exception itself still propagates and
cancels the query as before.

The failure is injected through the new failpoint
`executing_graph_add_node_fail`, and the gtest drives `ExecutingGraph`
directly, because the window between the two expansions cannot be hit
reliably through the executor. Without the guard the test reproduces the
logical error above.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [948c453]

Summary: ✅


AI Review

Summary

This PR hardens ExecutingGraph against exceptions during dynamic pipeline expansion: when recording a returned UpdatePipeline change throws halfway, the graph is marked as unusable for further expansions, the newly connected processors are kept alive, and later expansions bail out instead of walking a malformed port graph. I did not find any unresolved correctness, concurrency, or coverage issues in the current diff; the targeted gtest matches the reported failure mode, and the PR CI is all green.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit 948c453.

Metric Baseline Current Δ
Lines 88.00% 88.00% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 79.30% 79.30% +0.00%

Changed lines: Changed C/C++ lines covered: 26/26 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 22, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 948c45375 with master 5af633e4c (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

9 translation units recompiled, 15 s compile time in total, 9 of them have a recent master baseline.

Job report

@clickhouse-gh clickhouse-gh Bot added the comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. label Sep 22, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Perfect.

@alexey-milovidov alexey-milovidov self-assigned this Sep 22, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 22, 2026
Merged via the queue into master with commit c696743 Sep 22, 2026
176 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix/executing-graph-failed-expansion branch September 22, 2026 21:12
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 22, 2026
valerypetrov pushed a commit to valerypetrov/ClickHouse that referenced this pull request Oct 13, 2026
When recording the processors of a pipeline expansion throws (an allocation
fails on the memory limit, see ClickHouse#124906), `ExecutingGraph::updatePipeline`
marks the graph with `expansion_failed` and rethrows. Two things then go wrong.

1. The `nodes_mutex` write lock is released by unwinding before the exception
   reaches `PipelineExecutor::executeStepImpl`, which cancels the executor. A
   second thread can take the lock in that window, and `updateNode` returns
   `Cancelled` while the executor is not finished. `executeStepImpl` skipped
   `pushTasks` on a non-`Done` status, and `pushTasks` is the only thing that
   replaces the thread's task, so the loop ran `work` again on a processor that
   `updateNode` had just prepared. For `MergeSortingTransform` in `Serialize`
   the next `work` dereferences the `merge_sorter` the previous one reset
   (SIGSEGV in `MergeSorter::read`). Now the thread drops the task when
   `updateNode` does not return `Done`, so only the graph can schedule it.

2. The processors of the failed expansion were kept only in the graph, but the
   ports of the pipeline's own processors point at them, and the pipeline is
   read after the executor is destroyed: the exception callback logs the
   processors profile (ClickHouse#121503) after `LocalConnection` and `TCPHandler` have
   destroyed the executor, and `getProcessorsProfileLogInfo` reads the freed
   peer through the port (heap-use-after-free on every failed expansion under
   ASan). Now the processors the graph has not recorded yet are moved into the
   pipeline's shared processors list, so they live as long as the pipeline.

The new test runs the external sort with the `executing_graph_add_node_fail`
failpoint: the use-after-free reproduces on its first query under ASan, and
the race reproduces in 19 of 20 runs of the test on a debug build without the
first change.

Closes: ClickHouse#125251
Related: ClickHouse#121502
Related: ClickHouse#121503

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

Labels

comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. pr-bugfix Pull request with bugfix, not backported by default 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.

2 participants