Repository navigation
Report a distributed plan's root cause, not its exchange teardown error - #118417
alexey-milovidov wants to merge 2 commits into
Conversation
`04648_distributed_plan_task_error_propagation` asserts that a task failure recorded while the initiator is still dispatching a stage reaches the client as `CANNOT_SCHEDULE_TASK`. It started failing instead with `Code: 1000. DB::Exception: Net Exception: Failed to receive final_result__0_0 from 127.0.0.1:9223, peer closed connection. (POCO_EXCEPTION)`. `ReadFromDistributedPlanSource::tryGenerate` ran `cleanupLocked` before rethrowing. That cleanup reaches `ExchangeConnections::cleanupQuery`, which cancels the query's pending exchange connections and so closes the sockets that the streaming exchange sources of the *same* pipeline are reading. Those sources then throw a bare network error, and `PipelineExecutor` rethrows the exception of the first node in graph order that holds one - not the one raised first - so the teardown's error could replace the failure the query should report. Whether the source got that far before the driver finished unwinding is a race, which is why the test failed only sometimes. Rethrow before the cleanup on both paths and let `onCancel` do the teardown. `onCancel` is reached through `PipelineExecutor::cancel`, which finishes the task queue before cancelling the processors, so no source runs again to record the teardown's error - and a source can only become runnable once that teardown closes its socket. The ordering now holds by construction. The same runs also failed `04340_distributed_plan_status_reenqueue_fault`, which is the second half of the same defect. `04648` is a `.sql` test, so the unexpected error aborted it before its `SYSTEM DISABLE FAILPOINT`, leaving the server-wide `distributed_plan_record_failure_while_starting_tasks` armed for the rest of the job. Every later distributed-plan query then failed at task start, so `04340` never reached a status re-enqueue and reported `reenqueue fault handled: 0` eight minutes later. Make that fail point `ONCE` - the test injects exactly one failure - so a single injection can no longer leak into unrelated tests. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=f0346e63cbb865a81ad922cdc3c4c8bfbfffdb23&name_0=MasterCI&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20azure%2C%20sequential%29
|
Workflow [PR], commit [933a279] Summary: ❌
AI ReviewSummaryThis PR fixes the distributed-plan failure-ordering bug by deferring Missing context / blind spots
Final Verdict✅ No actionable findings at the current head. LLVM Coverage ReportMeasured on commit 933a279.
Changed lines: Changed C/C++ lines covered: 14/14 (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 units8 translation units recompiled, 9 s compile time in total, 8 of them have a recent master baseline. |
|
Checked #118390 at The fail point flip is not. Where that one line lands is your call. I can push exactly it to #118390 if you want it there; I have not touched that branch since you took it over and will not without your go-ahead. This PR reduced to the one line does the same job. One related thing in #118390: |
|
|
Superseded by #118390 |
Related: #118218
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a failing distributed-plan query sometimes reporting
Net Exception: Failed to receive <stream> from <host>:<port>, peer closed connectioninstead of the error that actually failed it.make_distributed_planis experimental.Description
04648_distributed_plan_task_error_propagationasserts that a task failure recorded while the initiator is still dispatching a stage reaches the client asCANNOT_SCHEDULE_TASK. It began failing on 2026-09-06 withReadFromDistributedPlanSource::tryGeneraterancleanupLockedbefore rethrowing. That cleanup reachesExchangeConnections::cleanupQuery, which erases the query's pending connection entries; destroying aFutureConnectiondrops the last reference to the acceptedStreamSocketand closes it. (Itscancelis a no-op once the connection has paired - the close comes from the erase, not fromcancel.) The peer of that socket is a streaming exchange source of the same pipeline, parked intryReadHeader, which then throwsPOCO_EXCEPTION.PipelineExecutorrethrows the exception of the first node in graph order that holds one, not the one raised first. So once both the driver and the exchange source hold an exception, which one the client sees is decided by node order, and the teardown's network error can displace the root cause.The fix rethrows before the cleanup on both paths and leaves the teardown to
onCancel.onCancelis reached throughPipelineExecutor::cancel, which callstasks.finish()beforegraph->cancel(), so no source is scheduled again to record the teardown's error - and a source can only become runnable once that teardown closes its socket.Measured, with a local instrumented build that forces the CI ordering (a delay either side of the teardown, and the teardown itself behind an env var), logging every graph node that holds an exception:
Three runs each. The competing exception no longer exists, so node order stops mattering. Note that on an uninstrumented local build the failure does not reproduce at all: the driver happens to sit at node 0 and wins the rethrow either way, which is why this needed the forced ordering to observe.
The same runs also failed
04340_distributed_plan_status_reenqueue_fault, which is the second half of the same defect rather than an independent flake.04648is a.sqltest, so the unexpected error aborted it before itsSYSTEM DISABLE FAILPOINT, leaving the server-widedistributed_plan_record_failure_while_starting_tasksarmed for the rest of the job. Every later distributed-plan query then failed at task start, so04340never reached a status re-enqueue and reportedreenqueue fault handled: 0eight minutes later. That fail point is nowONCE- the test injects exactly one failure - so a single injection cannot leak into unrelated tests. Verified directly: with the fail point armed the query returnsCANNOT_SCHEDULE_TASK, and the next query succeeds with noSYSTEM DISABLE FAILPOINTin between.No new test:
04648is already the regression test for this, and the change is what makes it deterministic. Both tests pass locally, and 200 consecutive injected-failure runs all reportCANNOT_SCHEDULE_TASK.Onset in CI,
Stateless tests (arm_asan_ubsan, azure, sequential), both tests:Every failing run reports the same two tests together. The ordering was racy in every version that has it, so this pins the ordering rather than reverting whatever tipped the timing; the linked pull request is the cancellation change that merged at that boundary, though it does not touch this code path.
One trade-off worth a reviewer's attention: deferring the teardown moves
cleanupinsideExecutingGraph::cancel, which holdsprocessors_mutex, andrunning_tasks.cancelwaits for workers to reach a terminal state. Every other cancellation path (KILL,LIMIT, another processor throwing) already ran the cleanup fromonCancelin exactly that position, so this is not a new hazard - but it is newly on the "the driver itself threw" path.Closes: #118831
Closes: #118832
Related: #118626
CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=f0346e63cbb865a81ad922cdc3c4c8bfbfffdb23&name_0=MasterCI&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20azure%2C%20sequential%29
Still failing on
masterat the same rate three days later, and the server log of that run confirms the whole chain in one place -Stateless tests (arm_asan_ubsan, azure, sequential)for1dd29f8: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=1dd29f83596b117a895338eabb68bcec75042885&name_0=MasterCI&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20azure%2C%20sequential%29CANNOT_SCHEDULE_TASKnever reaches the client in that run. Eight minutes later, at 19:05:50, all three of04340's queries fail withCode: 439. DB::Exception: Injected task failure while starting tasks-04648's leaked fail point - so no status re-enqueue ever happens and04340printsreenqueue fault handled: 0. Across the last three days onmaster, every failing run of that job reports exactly these two tests, and no other test hit the leaked fail point only because no other distributed-plan test ran inside the leak window.Note that the revert of the linked cancellation change (#118525, merged 2026-09-07) did not help: 23 failures per test on 2026-09-08 against 27 on 2026-09-07.
Workflow [PR]
Sync PR [sync-upstream/pr/118417]