Skip to content

Fix flaky test 04344_server_ast_fuzzer_insert_limit - #109209

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-04344-ast-fuzzer-sync-drop-timeout
Jul 10, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-04344-ast-fuzzer-sync-drop-timeout

Conversation

@groeneai

@groeneai groeneai commented Jul 2, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Description

Fixes a flaky Code: 159 TIMEOUT_EXCEEDED on the cleanup DROP TABLE of 04344_server_ast_fuzzer_insert_limit, seen on Stateless tests (amd_msan, WasmEdge, parallel, 2/2). 2 hits in 30 days (both on PR branches, 0 on master); reruns with the same randomized settings pass.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107087&sha=f3fd77f2195993b30398ef6e21e9cb45cc99e27e&name_0=PR&name_1=Stateless%20tests%20%28amd_msan%2C%20WasmEdge%2C%20parallel%2C%202%2F2%29

Root cause. The test sets ast_fuzzer_any_query = 1, so the server-side AST fuzzer clones each CREATE TABLE seed ~30 times, every clone reusing the real table's UUID and thus contending its store/<uuid>/ data directory. This slows the background atomic-drop worker for that UUID. The CI test profile forces database_atomic_wait_for_drop_and_detach_synchronously = 1 (tests/config/users.d/database_atomic_drop_detach_sync.xml) with database_atomic_delay_before_drop_table_sec = 60, so the trailing cleanup DROP TABLE waits in DatabaseCatalog::waitTableFinallyDropped for that worker. That wait is charged against the session SET max_execution_time = 20, and under the slowest sanitizer (msan + WasmEdge) it can exceed 20s and throw TIMEOUT_EXCEEDED on the DROP. The timeout is on cleanup, not on anything the test verifies.

Fix. Pin database_atomic_wait_for_drop_and_detach_synchronously = 0 before the teardown DROPs so they return without waiting for the background worker. The fuzzed SELECT/INSERT queries still run under max_execution_time = 20 and the fuzzer's own per-context resource caps, so the test still proves the server-side AST fuzzer honors the insert/read limits (reference output 4950 / 4950 / 4950 / 1 is unchanged).

Validation. Reproduced the mechanism locally against a server configured like CI (sync drop + 60s finalize delay), holding a table in the drop queue past a small max_execution_time:

  • without the fix (sync = 1): the DROP fails with Code: 159 TIMEOUT_EXCEEDED at the deadline;
  • with the fix (sync = 0): the DROP returns in ~65 ms.

Full test run against the CI-like server: 15/15 passes, output matches the reference, no TIMEOUT_EXCEEDED on any teardown DROP.

Version info

  • Merged into: 26.7.1.782 (included in 26.7 and later)

The test sets ast_fuzzer_any_query = 1, so the server-side AST fuzzer clones
each CREATE ~30 times reusing the real table's UUID. Those clones contend the
table's store/<uuid>/ directory, which slows the background drop worker.

Under the CI test profile database_atomic_wait_for_drop_and_detach_synchronously
is 1, so the trailing cleanup DROP TABLE waits in
DatabaseCatalog::waitTableFinallyDropped for that background worker. That wait
runs against the session max_execution_time = 20, and under the slowest
sanitizer (msan + WasmEdge) it can exceed 20s and fail with
Code: 159 TIMEOUT_EXCEEDED - a transient timeout on cleanup, not on anything the
test verifies.

Make the teardown DROPs asynchronous by pinning
database_atomic_wait_for_drop_and_detach_synchronously = 0 before them. The
fuzzed SELECT/INSERT queries still run under max_execution_time = 20 and the
fuzz-context resource caps, so the test still proves the server-side AST fuzzer
honors the insert/read limits; only the cleanup no longer blocks on the
synchronous drop wait.

Related: ClickHouse#108212

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

groeneai commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Against a server configured like CI (database_atomic_wait_for_drop_and_detach_synchronously = 1 + database_atomic_delay_before_drop_table_sec = 60), a DROP TABLE on a table held in the drop queue past a small SET max_execution_time = 3 fails with Code: 159 TIMEOUT_EXCEEDED every time.
b Root cause explained? ast_fuzzer_any_query = 1 makes the server-side fuzzer clone each CREATE ~30x reusing the real table's UUID -> those clones contend store/<uuid>/ -> the background atomic-drop worker for that UUID is slow -> the CI-forced synchronous teardown DROP waits in DatabaseCatalog::waitTableFinallyDropped, charged against the session max_execution_time = 20 -> under msan+WasmEdge the wait exceeds 20s -> TIMEOUT_EXCEEDED on cleanup.
c Fix matches root cause? Yes. The failure is the synchronous drop-wait, so the fix removes exactly that wait for the teardown DROPs (SET database_atomic_wait_for_drop_and_detach_synchronously = 0). It does not touch the fuzzer caps or max_execution_time that the test relies on.
d Test intent preserved / new tests added? Preserved. The fuzzed SELECT/INSERT queries still run under max_execution_time = 20 and the fuzzer's per-context resource caps, so the test still proves the server-side AST fuzzer honors the insert/read limits. The teardown DROPs do not contribute to the reference output (4950 / 4950 / 4950 / 1, unchanged).
e Both directions demonstrated? Yes. Same repro: sync = 1 -> DROP fails with Code: 159 at the deadline; sync = 0 -> DROP returns in ~65 ms. Full test against the CI-like server: 15/15 passes, output matches reference, no TIMEOUT_EXCEEDED on any teardown DROP.
f Fix is general across code paths? N/A (flaky test setting fix, not a code bug). The session SET covers both teardown DROPs in the test (t_04344_storage and the final t_04344).
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (flaky test setting fix, not a code bug).
h Backward compatible? (maintainer-approved exception only) N/A (flaky test setting fix, not a code bug; test-file only, no product behavior change).
i Invariants and contracts preserved? N/A (flaky test setting fix, not a code bug). The server-side fuzzer runs in throwaway copied contexts (executeASTFuzzerQueries), so the session-level SET applies only to the outer test session's teardown DROPs and cannot be mutated by fuzzed queries.

Session id: cron:clickhouse-worker-slot-0:20260702-175800

@groeneai

groeneai commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

cc @vdimir — could you review this test-only flaky fix? The server-side AST fuzzer clones each CREATE reusing the real table's UUID, which slows the background atomic-drop worker; under the CI-forced synchronous drop the teardown DROP then waits past the session max_execution_time = 20 and fails with Code: 159 (msan+WasmEdge only, 0 on master). The fix makes the teardown DROPs async without weakening what the fuzzer test verifies.

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Jul 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0fc750e]

Summary: ✅


AI Review

Summary

This PR makes the teardown in 04344_server_ast_fuzzer_insert_limit use asynchronous atomic drops by setting database_atomic_wait_for_drop_and_detach_synchronously = 0 before the cleanup DROP TABLE statements. That matches the failure mode described in the PR: the flake is in synchronous atomic-drop waiting under max_execution_time, while the query shapes this test is meant to validate still run under the existing AST-fuzzer resource caps. I did not find a remaining contract violation in the current diff.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.86% 85.88% +0.02%
Functions 91.47% 91.47% +0.00%
Branches 78.39% 78.43% +0.04%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 145 line(s), 4 function(s) across 56 file(s) · Details

Top files
  • src/Storages/WindowView/StorageWindowView.cpp: 22 line(s), 1 function(s)
  • src/Disks/IO/AsynchronousBoundedReadBuffer.cpp: 10 line(s)
  • src/Storages/StorageReplicatedMergeTree.cpp: 8 line(s)
  • src/Functions/s2GetNeighbors.cpp: 6 line(s)
  • src/Functions/array/arrayNormalizedGini.cpp: 5 line(s)

Full report

@groeneai

groeneai commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 0fc750e

Test-only PR (single .sql edit pinning database_atomic_wait_for_drop_and_detach_synchronously=0 on the teardown DROPs). All 11 other Stress variants (amd/arm debug, tsan, msan, release, arm asan/s3) passed; the single red leaf is the chronic stress-shutdown hung-check, which a .sql edit cannot cause.

Check / test Reason Owner / fixing PR
Stress test (amd_asan_ubsan) / Hung check failed, possible deadlock found deadlock (chronic stress-shutdown family) #108212 (ours, merged) / #105905 (ours, merged)
CH Inc sync private sync CH Inc sync (private, not actionable by us)

Session id: cron:our-pr-ci-monitor:20260702-230000

-- its store/<uuid>/ directory. With the CI's synchronous atomic drop a teardown DROP then waits for
-- the background worker to clear that directory, and under the slowest sanitizer that wait can pass
-- max_execution_time and fail with TIMEOUT_EXCEEDED. Teardown does not need to wait synchronously.
SET database_atomic_wait_for_drop_and_detach_synchronously = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this can happen with any test, can't it? And if it were correct we see the issue more often in CI since it's a common pattern for all tests.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, a plain CREATE+DROP cannot hit this. Three things have to line up, and only the server-side AST fuzzer tests have all three:

  1. max_execution_time = 20: a tight deadline this test sets to bound the fuzzer. A normal test leaves the default, so its teardown DROP has a far looser budget.
  2. ast_fuzzer_runs = 30 + ast_fuzzer_any_query = 1: the fuzzer runs in a query finish callback and clones+executes ~30 fuzzed queries after each statement. Under any_query = 1 those include the CREATE, whose AST is stamped in place with the table UUID (InterpreterCreateQuery: create.uuid = generateV4()), so the clones reuse it and contend store/<uuid>/, starving the background atomic-drop worker for that UUID.
  3. The CI profile forces database_atomic_wait_for_drop_and_detach_synchronously = 1, so the trailing DROP waits in DatabaseCatalog::waitTableFinallyDropped, and that wait is charged against the 20s deadline (throwIfKilled -> TIMEOUT_EXCEEDED).

Note the sync drop passes sync as ignore_delay to enqueueDroppedTableCleanup, so it is enqueued ahead of the 60s finalize delay and scheduled immediately. The >20s wait is therefore the background worker doing real work to clear store/<uuid>/, not the delay. For a generic test that worker finishes in milliseconds; here it is starved by the ~30 UUID-sharing fuzz clones. That is the specific difference.

Drop any one of the three and it does not fire, which is why it is rare (2 hits in 30 days, both on PR branches, 0 on master) rather than the universal failure a generic CREATE+DROP mechanism would produce. Only 7 of ~22,500 stateless tests set ast_fuzzer_runs at all, and just 2 executable ones set ast_fuzzer_any_query = 1.

Repro against a CI-like server (sync drop + 60s finalize delay), holding a UUID in the drop queue past a small max_execution_time: with sync=1 the DROP fails with Code 159 at the deadline; with sync=0 it returns in ~65ms.

The pin is teardown-only and does not change what the test verifies: the fuzzed SELECT/INSERT still run under max_execution_time = 20 plus the fuzzer's own resource caps, and the reference 4950/4950/4950/1 is unchanged. If you would rather keep the test untouched, the alternative is at the CI-profile/server level, but since only these fuzzer tests combine DDL fuzzing with the forced sync drop, the test-local pin is the least invasive correct fix.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, we can merge it. If this particular test appears to be bad, we can remove it.

@alexey-milovidov alexey-milovidov self-assigned this Jul 10, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 10, 2026
Merged via the queue into ClickHouse:master with commit 7a44236 Jul 10, 2026
344 of 345 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 10, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…t-fuzzer-sync-drop-timeout

Fix flaky test 04344_server_ast_fuzzer_insert_limit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants