Skip to content

Do not time out the async INSERT ... SELECT race tests when the insert ends between two polls - #122659

Merged
Felixoid merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-04633-async-insert-race-barrier
Sep 28, 2026
Merged

Felixoid merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-04633-async-insert-race-barrier

Conversation

@groeneai

@groeneai groeneai commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #111663
Related: #121687

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

04633_async_insert_select_alter_race failed in Stateless tests (amd_debug, parallel) on #121687 (an Iceberg change) with Timeout waiting for query insert_case3_... to start (job).

Root cause. wait_for_query_to_start polls system.processes until the query id appears, so it cannot tell "not started yet" from "already finished". In that run the first poll took its snapshot 40 ms before the INSERT registered, then stalled for 2.96 s. The INSERT (2.9 s) started and finished inside that gap, every later poll found nothing, and the 30 s budget ran out. The stall came from 01252_weird_time_zone's last query: on its first run after server start it builds a DateLUTImpl for every zone under DateLUT's global mutex, and any query with a session_timezone waits behind it (both queries had a random one).

Fix. wait_for_query_to_start takes an optional third argument, the PID of the client that runs the query. When a poll finds nothing and that client has exited, the query has already run, so the helper returns. Fixing only the stall would leave the barrier lossy against any other delayed poll. The 7 barriers in 04633_async_insert_select_{alter_race,freeze_race,late_bound_catalog} whose query is a short background INSERT pass $INSERT_PID: one helper change instead of 7 local ones. Their output does not depend on whether the DDL lands during or after the INSERT, and a failed INSERT still fails the test. Two-argument callers are unchanged, including the KILL QUERY barrier in 04633_async_insert_select_accounting, which needs its query alive.

Validation. A curl wrapper that delays the first poll of each query by 15 s reproduces the failure: master fails 9/9 with the CI message, this change passes 9/9, and each half alone still fails 9/9. 50/50 randomized runs of each changed test pass, and the whole 04633_async_insert_select family plus the 15 other tests with a wait_for_query_to_start barrier pass both before and after.


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

Version info

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

…ert ends between two polls

`wait_for_query_to_start` polls `system.processes` until the query id
appears, so it cannot tell a query that has not started from one that has
already finished. `04633_async_insert_select_alter_race` failed that way in
`Stateless tests (amd_debug, parallel)` on PR ClickHouse#121687: the first poll took its
`system.processes` snapshot 40 ms before the `INSERT` registered and then
waited 2.96 s on the global mutex of `DateLUT` (both queries had a random
`session_timezone`, and the last query of `01252_weird_time_zone` was building
a `DateLUTImpl` for every zone under that mutex). The `INSERT` ran for 2.9 s
inside that gap, every later poll found nothing, and the test exited after its
30 s budget with "Timeout waiting for query insert_case3_... to start".

The helper now takes an optional third argument, the PID of the client that
runs the query: when a poll finds nothing and that client has exited, the
query has already run, so the helper returns. The PID check comes before the
deadline check, so an exited client wins even after a stalled poll. The 7
barriers whose query is a short background `INSERT` (`alter_race` x4,
`freeze_race` x2, `late_bound_catalog` x1) pass `$INSERT_PID`. Their output does
not depend on whether the DDL lands during or after the `INSERT`, and a failed
`INSERT` still fails the test through its stderr and the row counts. Callers
with two arguments behave as before, including the `KILL QUERY` barrier in
`04633_async_insert_select_accounting`, which needs its query alive.

Verified with a `curl` wrapper that delays the first poll of each query by
15 s: master fails 9/9 with the CI message, this change passes 9/9, and each
half alone still fails 9/9.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=121687&sha=4686a70cd062c1eb96129f43bc5acc467f1b1539&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20parallel%29
Failing job: https://github.com/ClickHouse/ClickHouse/actions/runs/36367474392/job/108763115465
PR: ClickHouse#121687

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet labels Sep 28, 2026
@groeneai

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

Pre-publication review by an independent model (engine: codex; 1 finding).

# Sev Finding Verdict Evidence / action
1 ❌ When every poll misses the INSERT, the helper returns once the client exits and that run passes without exercising the race (tests/queries/shell_config.sh:196-198). Suggested: re-run a missed case until the INSERT is seen alive, failing after a bounded budget. DISAGREE On master that run is the false failure this PR fixes: it exits before its DDL, so it never exercised the race either. It is rare: 1 of 6,804 alter_race runs in 90 days, 0 of 6,742 freeze_race, 0 of 6,583 late_bound_catalog. Every other run is unchanged and does exercise the race: in the failing job's query_log, all 24 observed barriers had the DDL start 142-162 ms into a 2.0-4.4 s INSERT. I can add the re-run loop if preferred.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-10:20260928-100900

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. A curl wrapper delays the first system.processes poll of each query id by 15 s, so the INSERT ends before any poll sees it: master fails 9/9 with the CI message.
b Root cause explained? wait_for_query_to_start samples system.processes and cannot tell a finished query from one not yet started. In the failing job the first poll snapshotted 40 ms before the INSERT registered, then stalled 2.96 s on DateLUT's global mutex; the 2.9 s INSERT lived entirely in that gap.
c Fix matches root cause? Yes. The barrier now observes completion: after an empty poll, an exited client (kill -0 fails) means the query already ran. Independent of what stalls the poll; no timeout, bound, tag or data-size change.
d Test intent preserved / new tests added? Yes. When the barrier catches the INSERT running, the race is exercised as before; on a miss the DDL lands after the INSERT and the asserted output is the same. A failed INSERT still fails the test. No new test: the 7 barriers exercise the helper.
e Both directions demonstrated? Yes, under the same wrapper: master 9/9 FAIL, fix 9/9 OK; helper without the call-site argument 9/9 FAIL; the argument with master's helper 9/9 FAIL.
f Fix is general across code paths? Yes. One helper change covers all 7 short-INSERT barriers of the family. The KILL QUERY barrier and the 6 other callers of the helper keep the strict form, and 9 tests define their own copy; the family and those 15 tests pass identically before and after.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A for data types (test-only change). Argument matrix covered: 2 arguments (unchanged), 3 with a live client (keeps polling), 3 with an exited client (returns), empty third argument (old behaviour).
h Backward compatible? (maintainer-approved exception only) Yes. The argument is optional; every existing call behaves as before.
i Invariants and contracts preserved? Yes. The helper still returns only once the query was seen running or has provably run, and still exits 1 after the budget when the client is alive. A zombie costs one extra iteration; PID reuse falls back to today's timeout. wait "$INSERT_PID" still returns the client's status.

Session id: cron:clickhouse-impl-slot-6:20260928-090300

@clickhouse-gh

clickhouse-gh Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [42b42f8]

Summary: ✅


AI Review

Summary

This PR removes a real flaky timeout in the async INSERT ... SELECT race tests by teaching wait_for_query_to_start to stop waiting once the background client exits. The helper change is small, but it also weakens the affected race tests: under the same delayed-poll condition that triggered the original failure, they can now pass without ever proving that the DDL ran against an in-flight INSERT.

PR Metadata

Changelog category is correct: this is a CI Fix or Improvement, so no Changelog entry is required.

Findings

⚠️ Majors

  • [tests/queries/shell_config.sh:196-198] [dismissed by author -- https://github.com/Do not time out the async INSERT ... SELECT race tests when the insert ends between two polls #122659#issuecomment-5868504993] The new client_pid fast-path turns “the poll missed the whole query” from a loud failure into a silent pass. In cases 3-6, 9-10, and late-bound case 1, a stalled first poll can now return after the INSERT client has already exited, so the follow-up ALTER/CREATE MATERIALIZED VIEW runs after the INSERT finished and the race is never exercised. Before this patch the same condition failed loudly; after it, CI can go green without covering the concurrent-DDL contract these tests are meant to pin. Suggested fix: on the “unseen but already exited” path, rerun the case (or otherwise fail) until one poll actually observes the INSERT alive, instead of treating that path as a successful barrier.
Final Verdict

Changes need follow-up before merge: the timeout fix also makes the affected race tests able to pass without observing any in-flight query, which weakens the regression coverage they are supposed to provide.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 28, 2026
@groeneai
groeneai requested a review from Felixoid September 28, 2026 10:59
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Sep 28, 2026
@Felixoid

Felixoid commented Sep 28, 2026 •

Copy link
Copy Markdown
Member
  • [tests/queries/shell_config.sh:196-198] [dismissed by author -- https://github.com/Do not time out the async INSERT ... SELECT race tests when the insert ends between two polls #122659#issuecomment-5868504993] The new client_pid fast-path turns “the poll missed the whole query” from a loud failure into a silent pass. In cases 3-6, 9-10, and late-bound case 1, a stalled first poll can now return after the INSERT client has already exited, so the follow-up ALTER/CREATE MATERIALIZED VIEW runs after the INSERT finished and the race is never exercised. Before this patch the same condition failed loudly; after it, CI can go green without covering the concurrent-DDL contract these tests are meant to pin. Suggested fix: on the “unseen but already exited” path, rerun the case (or otherwise fail) until one poll actually observes the INSERT alive, instead of treating that path as a successful barrier.

The purpose is to WAIT for the query start. The function is called wait_for_query_to_start, not wait until query appears and stays in the process. Not our business here.

@Felixoid
Felixoid added this pull request to the merge queue Sep 28, 2026
Merged via the queue into ClickHouse:master with commit 16b5ba7 Sep 28, 2026
149 of 150 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 28, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Sep 28, 2026
Picks up ClickHouse#122659, which fixes the 04633_async_insert_select_late_bound_catalog
wait timeout that failed this PR's last CI run. No conflicts; the PR's own
change (FunctionToSubcolumnsPass.cpp and the 04692 test) is unchanged.
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-testing Test content only (no production code). groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet 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