Repository navigation
Fix flaky 03821_drop_workload_during_query_race leaking global workload state - #108978
Conversation
…ad state 03821 creates a root WORKLOAD and a (WORKER THREAD, MASTER THREAD) RESOURCE. Both are global server singletons. The test cleans them up in a trap on EXIT, but when it times out, clickhouse-test kills it with SIGTERM then SIGKILL after 0.1s, so the EXIT trap may not run and the root workload and thread resource leak on the shared sequential server. Every later no-parallel workload test on the same server then fails with BAD_ARGUMENTS: 'The second root is not allowed' (03232_workloads_and_resources, 03232_workload_create_and_drop) or 'The second resource for WORKER THREAD is not allowed' (03562_cpu_scheduling_with_one_thread). Observed on the arm_asan_ubsan azure sequential lane: 03821 times out, then those three fail together with return code 36, 0 failures on master. Bound every client invocation with a hard timeout so a query or DDL that wedges under the drop/create race cannot block 'wait' until the 180s test cap (where SIGKILL skips cleanup). The test then finishes normally and the EXIT trap always drops the workload and resource. Also run cleanup on TERM as a best-effort second line of defense. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-1:20260630-175800 |
|
cc @serxa — could you review? |
|
Workflow [PR], commit [4ac7111] Summary: ✅ AI ReviewSummaryThis PR tries to keep Findings
Tests
Final VerdictRequest changes. The simplified version is smaller, but it no longer demonstrates the timeout path is both fail-loud and leak-safe. |
CI finish ledger — 6fdc0c1Every failure below has an owner. This PR is a test-only change (
Session id: cron:our-pr-ci-monitor:20260703-053000 |
Pick up merged PR ClickHouse#108854 (fixes the flaky distributed 'expected TablesStatusResponse, got ProfileInfo' protocol desync) so CI re-runs against a base that includes the fix.
Ledger update —
|
| Check / test | Reason | Owner / fixing PR |
|---|---|---|
| Stateless (amd_asan_ubsan, distributed plan, 2/2) / 00211_shard_query_formatting_aliases | flaky distributed desync (expected TablesStatusResponse, got ProfileInfo); 36/36 reruns passed |
#108854 (merged) — merged master @ 6765854e to pick it up |
Session id: cron:clickhouse-worker-slot-3:20260703-055100
Addresses review feedback on PR ClickHouse#108978: the per-call `timeout` bound added to stop the drop/create race from hanging past the 180s test cap (where SIGKILL skips the EXIT trap and leaks the global root workload and thread resource) also swallowed timeout(1)'s exit 124, so a real 30s deadlock of a query or DDL would now pass silently, hiding exactly the hang this test surfaces. Capture 124 from each bounded call (PIPESTATUS[0] in thread_query, || rc=$? in thread_drop_create) into a per-run flag file, and fail after `wait` if it is set. Healthy runs never hit the 30s bound, so no false positives; the EXIT/TERM trap clears the flag so a leaked flag can never fail a later run on the shared sequential server. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Address review feedback on the per-call timeout in 03821_drop_workload_during_query_race. Plain `timeout` only sends a soft TERM and waits for the child, so a clickhouse-client stuck in the bad state this test defends against could ignore TERM and block until the outer test cap, which skips the EXIT trap and leaks the global root workload / thread resource. Use a real hard bound (`timeout --signal=TERM --kill-after=5`) via a `bounded` helper for every client call, and treat both exit 124 (TERM) and 137 (KILL after the grace) as a wedge. A client killed by timeout can leave its query still running server-side (see wait_for_queries_to_finish in shell_config.sh). Cleanup now kills any lingering query in the test's unique database first, then runs the DROP WORKLOAD / DROP RESOURCE under the same hard bound, so cleanup itself cannot hang past the outer cap and recreate the leak it is meant to fix. Co-Authored-By: Claude Opus 4.8 <[email protected]>
kill_lingering_queries filtered by current_database = currentDatabase(), but clickhouse-test runs each shell test in a fresh random database while wl_03821 / rs_03821 are global server singletons. A query leaked by an earlier timed-out invocation lives in a different database, so the next invocation's cleanup missed it and the shared sequential server stayed poisoned. Match by the fixed object name in system.processes.query instead, so cross-invocation lingering work is killed regardless of its database. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The setup CREATE OR REPLACE RESOURCE/WORKLOAD was the last unbounded client call. If it wedged on the same scheduler state the test defends against, it could block until the outer test cap SIGKILLs the shell (skipping the EXIT trap) after a global singleton was already created, reintroducing the leaked global workload/resource on the shared sequential server. Run it through the same hard-bound bounded() helper and fail on 124/137. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
@groeneai This is now overly complicated after you addressed the feedback. Can we simplify it? I liked the initial version that was available when I approved. Is there a real reason for all this complications? If not - keep it simple |
kill_lingering_queries runs inside cleanup (top of the script and on EXIT). KILL QUERY ... SYNC returns kill_status rows on stdout when it actually kills a leaked query, so the cross-invocation self-heal would print those rows and break the reference (which is only the final `1`). Discard them with FORMAT Null; the leaked query is still killed. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-3:20260703-111700 |
The root-cause fix is bounding every client call with `timeout` so no wedged query/DDL blocks `wait` until the outer test cap, where SIGKILL skips the EXIT trap and leaks the global root workload and thread resource. That version was reviewed and approved. Subsequent bot review rounds added a hard-kill wrapper, a cross-invocation kill-lingering-queries self-heal, wedge-flag fail-loud detection, setup-DDL bounding, and KILL QUERY output suppression. None are load-bearing for the leak fix, and the self-heal path does not fit under the 180s watchdog, so drop them and keep the simple version. Verified: 50/50 runs pass with randomization; zero leaked wl_03821 / rs_03821 and zero lingering server-side queries afterward. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
@serxa Done in 3399277. Reverted the test to exactly the version you approved (6765854). The leak fix is only this: bound every client call with The later rounds (hard-kill Verified 50/50 runs with randomization, zero leaked wl_03821 / rs_03821 and zero lingering server-side queries afterward. Diff is back to +10/-5. |
|
Pre-PR validation gate for the simplification (commit 3399277): Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-4:20260703-121000 |
LLVM Coverage Report
Changed lines: No C/C++ source files changed — skipping uncovered code analysis. Newly covered by added/modified tests: 84 line(s), 25 function(s) across 42 file(s) · Details Top files
|
CI finish ledger — 3399277Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
This PR's diff is a test-only Session id: cron:our-pr-ci-monitor:20260703-163000 |
|
Fixing PR for the 02473_optimize_old_parts flaky (amd_tsan s3 storage result-diff on this PR's CI): #109344 |
|
Ledger update for the |
CI finish ledger — 4ac7111Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task All 174 checks completed with no failures.
Session id: cron:our-pr-ci-monitor:20260729-053000 |
Antalya 26.6 Backport of ClickHouse#108978 - Fix flaky 03821_drop_workload_during_query_race leaking global workload state
Related: #108049
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Fix for the workload/scheduler test cluster flake alexey-milovidov asked me to investigate in a separate PR (CI triage on #108049). No tracking issue existed.
03821_drop_workload_during_query_racecreates a rootWORKLOAD wl_03821and aRESOURCE rs_03821 (WORKER THREAD, MASTER THREAD). Both are global server singletons (enforced inWorkloadEntityStorageBase::storeEntityImpl). The test drops them in atrap cleanup EXIT, but on timeoutclickhouse-testsends SIGTERM then SIGKILL 0.1s later, so the EXIT trap may not run and the root workload + thread resource leak on the shared sequential server.Every later
no-parallelworkload test on that server then fails:03232_workloads_and_resources,03232_workload_create_and_drop:CREATE OR REPLACE WORKLOAD all->BAD_ARGUMENTS: The second root is not allowed. You should probably add 'PARENT wl_03821' clause.03562_cpu_scheduling_with_one_thread:CREATE OR REPLACE RESOURCE ... (WORKER THREAD, MASTER THREAD)->BAD_ARGUMENTS: The second resource for WORKER THREAD is not allowed.This is exactly the cluster seen on
Stateless tests (arm_asan_ubsan, azure, sequential):03821times out, then the three fail together with return code 36, 0 failures on master, reproduced on unrelated PR #108084.Root cause: the test can hang past the 180s per-test cap (a query/DDL wedges under the drop/create race), gets SIGKILLed, and the EXIT-trap cleanup never runs. Fix: bound every client invocation with a hard
timeoutso no single wedged call can blockwaituntil the cap. The test then always finishes normally and the EXIT trap always drops the workload and resource. Also clean up on TERM as a best-effort second line of defense.Reproduced locally (debug build): a leaked
wl_03821/rs_03821deterministically produces the two errors above; the patched test passes 50/50 with randomization and leaves zero workloads/resources behind.Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108049&sha=a064fd421a09493c119fc473ef63c94064a6ca75&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20azure%2C%20sequential%29
Version info
26.8.1.361(included in26.8and later)