Skip to content

Fix flaky 04633_async_insert_select_general (no deadline on the wait_for_async_insert=0 poll) - #124263

Merged
Felixoid merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-04633-async-insert-select-general
Oct 8, 2026
Merged

Felixoid merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-04633-async-insert-select-general

Conversation

@groeneai

@groeneai groeneai commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #119181

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):

Fix flaky test 04633_async_insert_select_general.

Description

Case 4 of 04633_async_insert_select_general (an HTTP INSERT ... SELECT with async_insert=1&wait_for_async_insert=0) failed on #119181 with the two wait_* rows missing (report).

The rows were not lost. In that job's logs the background flush started 1 ms after the INSERT and took 27.4 s, 27.1 s of it waiting for the filesystem cache priority lock (FilesystemCachePriorityWriteLockMicroseconds) while writing a 2-row part to the write-through cached_azure disk; Azure writes took 5 ms. The test polls count() only 20 times (about 19 s on that lane), so it printed nothing; the part committed 8 s after the final SELECT.

wait_for_async_insert=0 gives no visibility deadline, so the 20-iteration cap checks nothing about the feature. The poll now loops until the rows land, and the runner's per-test timeout stays the bound, so a lost insert still fails. Same approach as #123897. Test-only, reference unchanged.

Validation on a master debug build, with the case-4 table on a write-through cache disk and its part write held for 30 s by the file_segment_pause_before_write failpoint: the old test fails 3/3 with exactly the CI diff, the new one passes 3/3; with the write never released, the new test fails on the runner timeout. The fixed test passes 50/50 with randomized settings and 20/20 with local_cache as the default storage policy.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/124263]

Version info

  • Merged into: 26.10.1.1821-master (included in 26.10 and later)

…for_async_insert=0 poll

Case 4 inserts with `async_insert=1&wait_for_async_insert=0` and then polled
`count()` 20 times (about 19 s on the arm_asan_ubsan azure lane) before printing
the rows. `wait_for_async_insert=0` gives no visibility deadline, and on ClickHouse#119181
the background flush took 27.4 s, 27.1 s of it waiting for the filesystem cache
priority lock while writing a 2-row part to the write-through `cached_azure` disk
(Azure writes took 5 ms). The rows landed 8 s after the final SELECT, so the
reference diff was caused only by the 20-iteration cap.

Loop until the rows land instead. The runner's per-test timeout stays the bound,
so a lost insert still fails. Same remedy as ClickHouse#123897.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Oct 6, 2026
@groeneai

groeneai commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (1 nit).

# Sev Finding Verdict Evidence / action
1 💡 With no iteration cap, a genuinely lost insert now fails as a runner timeout (600 s) instead of a reference diff after about 19 s AGREE, not blocking Still red: with the write never released the test fails with Timeout! Killing process group. Same trade-off as #123897.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding. Findings on hunks unchanged by the fix round are auto-dropped.

Session id: cron:clickhouse-review-slot-8:20261006-155500

@groeneai

groeneai commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Case-4 table on a write-through cache disk (local_cache), part write held 30 s by the file_segment_pause_before_write failpoint: the old test fails 3/3 with exactly the CI diff (0 wait_0 / 1 wait_1 missing).
b Root cause explained? A wait_for_async_insert=0 flush can take longer than case 4's 20-iteration poll (about 19 s). In the CI job the flush took 27.4 s, 27.1 s of it on the filesystem cache priority lock while writing to cached_azure; the rows committed 8 s after the final SELECT.
c Fix matches root cause? Yes. wait_for_async_insert=0 has no visibility deadline, so the cap asserted nothing; the poll now loops until the rows land, bounded by the runner's per-test timeout. No tag, setting pin or widened bound.
d Test intent preserved / new tests added? Yes. Case 4 still waits for the rows and checks them against the unchanged reference. With the write never released, the test fails on the runner timeout.
e Both directions demonstrated? Yes. Same rig and binary: old 3/3 FAIL, new 3/3 OK, every run with the case-4 flush stalled for 30 s.
f Fix is general across code paths? Yes for this test: cases 1 and 3 poll after a wait_for_async_insert=1 insert with a synchronous SYSTEM FLUSH LOGS. Other tests with a bounded wait_for_async_insert=0 loop have no failures in 30 days; not touched.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only). 50/50 OK with randomized settings, 20/20 OK with local_cache as the default storage policy.
h Backward compatible? (maintainer-approved exception only) N/A (test-only; no setting, format or default change).
i Invariants and contracts preserved? Yes. The test's contract (rows land and match the reference) is unchanged; only the arbitrary deadline is removed.

Session id: cron:clickhouse-impl-slot-4:20261006-152700

@clickhouse-gh

clickhouse-gh Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3e98dd7]

Summary: ✅


AI Review

Summary

This PR removes the arbitrary 20-iteration polling deadline from case 4 of 04633_async_insert_select_general, so the test now waits for the wait_for_async_insert=0 insert to become visible instead of assuming a ~19 s upper bound. I reviewed the current one-file diff, the surrounding test logic, the prior PR discussion, and the available CI signal, and I did not find a correctness, coverage, or contract regression in the change.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 6, 2026
@groeneai
groeneai requested a review from Felixoid October 6, 2026 16:23
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 6, 2026
${CLICKHOUSE_CURL} -sS -X POST \
"${CLICKHOUSE_URL}&async_insert=1&wait_for_async_insert=0&query=${Q}" -d ""

for _ in $(seq 1 20); do

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.

So, we only time out here?

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.

Yes, deliberately. With wait_for_async_insert=0 nothing bounds when the flush finishes. On #119181 it started 1 ms after the INSERT and took 27.4 s, 27.1 s of that waiting for the filesystem cache priority lock on the write-through cached_azure disk, so the rows landed 8 s after the test's final SELECT. A fixed in-test bound only moves that threshold, so a lost insert now fails as this test's 600 s runner timeout.

SYSTEM FLUSH ASYNC INSERT QUEUE test_async_sel_wait would not make it deterministic: the table-scoped flush waits only for batches it takes from the queue itself, and this batch was already scheduled (AsynchronousInsertQueue::flush). If you prefer an explicit bound with a readable failure, I can switch to that.

@Felixoid
Felixoid added this pull request to the merge queue Oct 8, 2026
Merged via the queue into ClickHouse:master with commit 6c500b9 Oct 8, 2026
149 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 8, 2026
@clickhouse-gh clickhouse-gh Bot added comp-async-insert Asynchronous INSERT buffering/queueing and flush semantics. and removed comp-testing Test content only (no production code). labels Nov 22, 2026
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 comp-async-insert Asynchronous INSERT buffering/queueing and flush semantics. groeneai-origin-request PR origin: a maintainer pinged or directed groeneai 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.

3 participants