Repository navigation
Do not lose the LIMIT stop of a distributed-plan in-memory exchange when its port closes concurrently - #122453
Conversation
SourceFromInMemoryExchange::prepare decided the reader detach on one read of its output port and then returned ISource::prepare, which reads the port again and returns Finished. Executor threads prepare connected processors concurrently (ExecutingGraph::updateNode takes only a shared nodes_mutex plus the node's own status_mutex) and InputPort::close is a lock-free flag update, so a LIMIT or join closing its inputs between the two reads finished the source without detachReader. A Finished node ignores later port updates, so the producer's SinkFromInMemoryExchange never saw isReaderDetached and its stage, and every stage feeding it, read their whole input. The race exists since the detach was added in dd3d060. Until ClickHouse#117661 the unconditional cancel in ~CompletedPipelineExecutor ran onCancel, and with it detachReader, at the end of every consumer task, which bounded it; since then the producer runs to the end of its input. On master this shows as 04891_distributed_plan_limit_early_stop failing its local arm after ~100 s with one exchange path missing from the stop oracle. Decide the detach on the result of ISource::prepare: Finished while the source has not ended by itself means the port was closed. A source that ends with its data still logs nothing, which the oracles rely on. The remote arm of the same test also failed once with unexpected=['exchange_1__0_0']: under TSan a dimension reader started late, the LIMIT fired while that join bucket was still reading its build side, and the stop correctly closed that input too. So both 04891 and 05024 now allow, but do not require, the dimension-table shuffles (exchange_1 in 04891, exchange_1 and exchange_3 in 05024, derived from the task layouts of 46 runs with no variation). Validated with a temporary 5 ms sleep between the two reads: unfixed 17/17 runs of 04891 red on the local arm (~104 s), fixed 20/20 green with the same sleep. Without it: 100/100 randomized runs of both tests, 200/200 at -j 16, and both tests still red with the probe table cut to one block. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding), plus my own cold review (1 nit shown).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20260926-175300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20260926-165500 |
|
Workflow [PR], commit [b674bdf] Summary: ✅
AI ReviewSummaryThis PR fixes a real race in PR Metadata
Final Verdict
LLVM Coverage ReportMeasured on commit b674bdf.
Changed lines: Changed C/C++ lines covered: 6/6 (100.00%) · 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 units7 translation units recompiled, 15 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - 692be26Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
All 173 check runs completed (129 pass, 41 not selected, 3 red), Session id: cron:our-pr-ci-monitor:20260927-020134 |
Related: #117764
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
04891_distributed_plan_limit_early_stopfails on master in two ways since #117764 made it assert the stop per exchange stream:MISMATCH missing=[...]after ~100 s: master, amd_debug, master, amd_tsan, #121119, amd_debug. One in-memory exchange source finished without detaching its reader, so its producer stage and every stage feeding it read their whole input.unexpected=['exchange_1__0_0']: master, amd_tsan. The engine was right: theLIMITfired while a join bucket was still reading its build side, and the stop closed that input too.Root cause of the first:
SourceFromInMemoryExchange::preparedecided the detach on one read of its output port, thenISource::prepareread the port again and returnedFinished. Executor threads prepare connected processors concurrently andInputPort::closeis lock-free, so a close landing between the two reads finished the source withoutdetachReader, and a finished node is never prepared again. The race exists since the detach was added indd3d060e23c4; #117661 removed the executor teardown cancel that used to detach at the end of the consumer task, which turned it into a 100 s stall.Change: the detach is decided on the result of
ISource::prepare(Finishedwhile the source has not ended by itself). Both tests now allow, but do not require, the dimension-table streams.Validation on a debug build: with a 5 ms sleep between the two reads, the unfixed code fails 17 of 17 runs of 04891 (local arm, ~104 s); the same sleep in the fixed code passes 20 of 20 with all 12 streams stopped. Without the sleep, 100 of 100 randomized runs of both tests pass, 200 of 200 at
-j 16, and both tests still fail when nothing is stopped (probe table cut to one block).Workflow [PR]
Sync PR [sync-upstream/pr/122453]
Version info
26.10.1.1466-master(included in26.10and later)