Repository navigation
Fix deadlock in ProcessList::killAllQueries with distributed query plans - #128832
Conversation
…plans `killAllQueries` marked all queries with `is_cancelling` first, then cancelled them one by one, and unmarked them only at the end. Cancelling a query with a distributed query plan joins the threads of its local tasks, and each of them has its own process list entry, whose destructor waits while the entry is marked. So the cancellation never finished: on shutdown (and in `OOMCanary`) the server hung forever. Mark, cancel and unmark the queries one at a time, as `killQuery` does. Found by `La Casa Del Dolor (amd_debug)` (the server did not shut down): https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=c081bf46d4ef8e43e4916890b638c3139f538720&name_0=MasterCI&name_1=La%20Casa%20Del%20Dolor%20%28amd_debug%29 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [fa6fd89] Summary: ✅
AI ReviewSummary
Missing context / blind spots
Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units7 translation units recompiled, 10 s compile time in total, 7 of them have a recent master baseline. |
…an executed locally `killAllQueries` on shutdown hung on such a query: its local tasks have their own process list entries, and cancelling the query joins their threads. The test starts the query, waits until the local tasks read, shuts the server down and checks that it stops gracefully. Without the fix the helper has to kill the server after `shutdown_wait_unfinished`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/Interpreters/ProcessList.cpp
|
🕵 Merged CI failures on the previous heads are unrelated to this change, which only touches
@groeneai, investigate the |
|
The fix is in progress: #125542. Cause: #4 (and #8, the same query with Breadth (CIDB #125542 fills runs of all-blank 64-row blocks with one |
|
🕵 Merged @groeneai, thanks for the analysis of |
|
🕵 The only red job on 5af3c16 is |
|
🕵 Merged |
ProcessList::killAllQueriesmarked all queries withis_cancellingfirst, then cancelled them one by one, and unmarked them only at the end. Since #120949 each local task of a distributed query plan has its own process list entry, and cancelling the query joins the task threads (ReadFromDistributedPlanSource::onCancel->DistributedQueryPlanExecutorLocal::cleanup->joinAllThreads). A task thread that finishes destroys itsProcessListEntry, whose destructor waits while the entry is marked; the entry stays marked until all cancellations are done, so the cancellation never finishes. The server hung on shutdown forever (andOOMCanary, which also callskillAllQueries, would hang too).Now
killAllQueriesmarks, cancels and unmarks the queries one at a time, askillQueryandsendCancelToPostgreSQLQuerydo, and skips the queries that finished since the list was taken.Found by
La Casa Del Dolor (amd_debug), where the server did not shut down: the main thread was inProcessList::killAllQueries->DistributedQueryPlanExecutorLocal::joinAllThreads, and theDistQueryTaskthreads inProcessListEntry::~ProcessListEntry.https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=c081bf46d4ef8e43e4916890b638c3139f538720&name_0=MasterCI&name_1=La%20Casa%20Del%20Dolor%20%28amd_debug%29
Checked locally: a server running
SELECT sum(a.x + b.x) FROM big AS a JOIN big AS b ON a.y % 10 = b.y % 10 SETTINGS make_distributed_plan = 1, distributed_plan_execute_locally = 1(8 process list entries) still ran 90 s after SIGTERM without the fix (shutdown_wait_unfinished = 5); with the fix it cancelled the query and exited normally in 5 s. Added an integration test totest_shutdown_wait_unfinished_queriesthat shuts the server down while such a query runs and checks that it stops without being force-killed; it fails without the fix and passes with it.Related: #120949
Related: #128774
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix the server hanging forever on shutdown while a query with
make_distributed_plan = 1is running.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/128832]
Version info
26.11.1.1950-master(included in26.11and later)