Repository navigation
Fix Crash during Traversal of Execution Graph - #118031
Conversation
|
Workflow [PR], commit [76d81d5] Summary: ✅
AI ReviewSummaryThis PR changes Tests
Final VerdictStatus: LLVM Coverage ReportMeasured on commit 76d81d5.
Changed lines: Changed C/C++ lines covered: 58/59 (98.31%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units18 translation units recompiled, 51 s compile time in total, 14 of them have a recent master baseline. Translation units without a recent master baseline:
|
b72b7e7 to
3114157
Compare
| read_lock.lock(); | ||
| } | ||
|
|
||
| if (updated_processors.empty() && updated_edges.empty()) |
There was a problem hiding this comment.
This bottom-of-loop defer is the whole fix for the new lifetime contract, but the PR still ships without a focused regression that proves it. The existing gtest_update_pipeline cases cover single-frame fan-in removal, deferred removal of unfinished processors, and cancellation stranding; they do not park a second executor frame across this gap, and they do not exercise the allocation-failure path the second commit is explicitly about. Please add a targeted ASan/TSan or deterministic repro here, or equivalent focused evidence for why both the cross-frame case and the throw-before-cleanup path stay covered by this rewrite.
yariks5s
left a comment
There was a problem hiding this comment.
Looks good, though we can add a regression test (optional)
|
Don't know how to write a non-hacky test for this, but the fix is straightforward - we do not release the lock while we have pointers to shared state. |
IProcessor::work() runs with no graph lock held: PipelineExecutor::executeStepImpl
calls context.executeTask() at PipelineExecutor.cpp:356 and only enters
graph->updateNode at :379. That is why IProcessor.h:189-194 states that work()
cannot access any ports.
Two processors broke that contract. ScatterByPartitionTransform::work() pushed to
its output ports, and OutputPort::pushData -> Port::updateVersion ->
Port::UpdateInfo::update appends to the node's own post_updated_output_ports,
which ExecutingGraph::addEdges wired as that edge's update list. A peer worker
reclaiming a retired processor holds the nodes_mutex write lock and sweeps every
node (removePendingGroup -> removeAffectedEdges), std::erase_if-ing the same
vector. The AST fuzzer reported the resulting data race on amd_tsan; besides the
sanitizer report, a concurrent push_back and erase_if on one std::vector<void *>
can drop or duplicate an edge id or leave a freed Edge * behind. The scatter is
reachable from ordinary SQL: SortingStep::scatterByPartitionIfNeeded inserts it
for any window-function sort with a non-empty PARTITION BY, for hash-sharded
merge joins and for distributed shuffle.
CreatingSetsTransform::work() closed its input port, the same violation on the
set-building path for IN (subquery) and external tables.
Both now do their port work in prepare(), which runs under the graph lock, so
ExecutingGraph needs no change: with the contract honoured, every writer of
post_updated_*_ports runs under nodes_mutex and its write lock is exclusive as
designed. This follows CopyTransform, the contract-conforming fan-out shape.
The scatter keeps the hashing and IColumn::scatter work in work() and hands the
chunks over from prepare(); a single has_output_chunks flag replaces the former
has_data (write-only) and all_outputs_processed pair. prepare() cannot observe a
pulled-but-unscattered chunk, because it only returns Ready right after pulling
and the owning thread runs work() before its next prepare(). Returning PortFull
while chunks are pending preserves the ordering that
optimizeJoinByShards.cpp:549-558 documents as deadlock-relevant: no new input
chunk is consumed until every partition chunk of the previous one is handed over.
CreatingSetsTransform now closes its input one prepare() later on the path that
stops consuming early (the set came from the cache), so the subquery upstream may
produce at most one more chunk, which is discarded when the port closes. That
window already existed between prepare() returning Ready and work() running.
The close cannot be dropped altogether: generate() always returns {}, so
finished_generate is set in the same work() call and the base class returns
through its finished_generate branch, which does not close the input.
An exhaustive scan of the other methods that run outside nodes_mutex found no
further violation: every other void work() body in src/, all 21 onCancel()
overrides, both onAsyncJobReady() overrides and schedule()/scheduleForEvent().
Tests: a TSAN gtest that runs a scatter next to pipeline-update removal churn on
16 threads and reproduces the reported race before the fix; a round-robin case
asserting that a finished output does not wedge the pipeline; and a hash-mode
case asserting that prepare() reports PortFull, rather than consuming another
input chunk, while a scattered chunk is still pending.
Related: ClickHouse#118031
Related: ClickHouse#118393
Co-Authored-By: Claude Opus 5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
This patch improves lock lifetime held during graph traversal.
Fixes: #116103
Workflow [PR]
Sync PR [sync-upstream/pr/118031]
Version info
26.9.1.773(included in26.9and later)