Skip to content

Fix flaky test 02122_join_group_by_timeout - #109584

Merged
alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-flaky-02122-join-group-by-timeout
Jul 30, 2026
Merged

alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-flaky-02122-join-group-by-timeout

Conversation

@groeneai

@groeneai groeneai commented Jul 6, 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

Flaky in Stateless tests (amd_tsan / amd_msan): intermittently the Code: 159
timeout line is missing from the output (result differs with reference, -Code: 159
in the diff). 0 master failures; CI rerun diagnosis always reports "not reproducible".

Root cause: the HTTP part of the test runs the query through curl --max-time $TIMEOUT
with TIMEOUT=5 (release) / 15 (sanitizer/debug), but the test's own duration
assertion accepts cancellation taking up to 60s (query_duration BETWEEN 1 AND 60).
When cancellation is legitimately slow under sanitizer load (still well within the
accepted 60s window), curl hits its --max-time cap and closes the connection before
the server delivers the Code: 159 timeout error, so that line is dropped from the
output while the run would otherwise have passed. The curl cap was inconsistent with
the window the test itself accepts.

Fix: set TIMEOUT=90 unconditionally so curl --max-time always exceeds the 60s
duration window the test accepts. 90s > 60s already covers sanitizer/debug slowness,
so the separate sanitizer branch is no longer needed. The cancellation assertions are
unchanged, so the test still verifies exactly the same behavior.

Reproduced the mechanism locally: with a delayed Code: 159 delivery and a tight
curl --max-time, the line is truncated (bug); with a generous --max-time the line
is present (pass). 20/20 passes with the fix.

Version info

  • Merged into: 26.8.1.464 (included in 26.8 and later)

@groeneai

groeneai commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. With a delayed Code: 159 delivery (a query whose max_execution_time=1 exception surfaces after ~5s) and curl --max-time 2, the Code: 159 line is deterministically truncated/missing; with curl --max-time 30 it is deterministically present.
b Root cause explained? The HTTP client runs via curl --max-time $TIMEOUT (5s release / 15s sanitizer). The test's own duration assertion accepts cancellation up to 60s (query_duration BETWEEN 1 AND 60). Under sanitizer slowdown, cancellation can legitimately take >15s but <60s; curl hits its cap and closes the connection before the server delivers Code: 159, dropping that line -> result differs with reference.
c Fix matches root cause? Yes. Set TIMEOUT=90 so curl --max-time exceeds the 60s window the test itself accepts, removing the inconsistency. Not a bounds-widen or a no-random-* band-aid.
d Test intent preserved / new tests added? Yes. The cancellation assertions (Code: 159, query_duration BETWEEN 1 AND 60, break-mode return code 0) are unchanged. Only the curl connection cap is raised, so the test still verifies identical timeout behavior.
e Both directions demonstrated? Yes. Truncated (fail) with tight --max-time; present (pass) with generous --max-time. Test run 20/20 pass with the fix.
f Fix is general across code paths? N/A (flaky test setting fix, not a code bug).
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).
i Invariants and contracts preserved? N/A (flaky test setting fix, not a code bug).

Session id: cron:clickhouse-worker-slot-2:20260706-224000

@groeneai

groeneai commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

cc @vdimir — could you review this? It fixes flakiness in the HTTP part of the test: curl --max-time (5s/15s) was tighter than the test's own accepted cancellation window (query_duration BETWEEN 1 AND 60), so a legitimately-slow-but-passing timeout under sanitizer load got its connection cut before the server delivered Code: 159. Raised the curl timeout to 90s; assertions unchanged.

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

clickhouse-gh Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [eeadb5b]

Summary: ✅


AI Review

Summary

This PR removes the per-test HTTP curl --max-time override from 02122_join_group_by_timeout, adds query_id-based duration checks for the HTTP paths, and polls system.query_log before asserting so delayed log commits no longer drop the query_duration lines. I rechecked the final script against the current diff, the prior inline threads, and the current all-green CI, and I did not find any remaining correctness or coverage gaps in the current revision.

Final Verdict

✅ No new blocking or major issues found in the current revision.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 7, 2026
@groeneai
groeneai force-pushed the groeneai/fix-flaky-02122-join-group-by-timeout branch from e000ac7 to 4421a3a Compare July 7, 2026 09:00
@groeneai

groeneai commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

Good catch, adopted option (a). Dropped the per-test `--max-time` override entirely so both HTTP calls inherit the harness `${CLICKHOUSE_CURL}` (`--max-time 120`); removed the `TIMEOUT` variable. This removes the second client-side cutoff below the harness cap that `TIMEOUT=90` still left.

The query_duration BETWEEN 1 AND 60 assertions remain the real correctness cap and are unchanged: if the HTTP path ever surfaces Code: 159 in the 91-120s range, the duration assertion fails loudly rather than the line being silently truncated. Test passes 20/20 locally (debug). Pushed as 4421a3a.

@groeneai
groeneai force-pushed the groeneai/fix-flaky-02122-join-group-by-timeout branch from 4421a3a to 4cd796c Compare July 7, 2026 10:17
@groeneai

groeneai commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed. Both HTTP calls now set an explicit query_id and assert round(query_duration_ms/1000) BETWEEN 1 AND 60 from system.query_log after SYSTEM FLUSH LOGS query_log, mirroring the existing TCP-path assertions. So the HTTP cancellation window is still actively tested: a timeout-delivery regression into the 90-119s range (which the harness 120s cap would otherwise let pass silently) now fails the duration assertion loudly. Kept the truncation fix (no per-test --max-time override; HTTP inherits the harness 120s cap).

Verified locally on the debug binary (buildId 775D531E): test passes 20/20; the HTTP timeout query logs ExceptionWhileProcessing at query_duration_ms=1000 -> assertion prints query_duration 1 (matches reference), while an out-of-window (<1s) query yields query_duration 0 -> would break the reference loudly.

The test verifies a JOIN+GROUP BY query respects max_execution_time and is
cancelled with Code: 159 (HTTP and TCP clients, plus the break-mode variant).

Two independent flakes were addressed:

1. curl truncation. A per-test curl --max-time cap (5s release / 15s sanitizer)
   was below the 1..60s cancellation window the test itself asserts, so under
   sanitizer/overload the connection closed before the server delivered
   Code: 159, dropping that line. Fixed by removing the per-test override so the
   HTTP calls inherit the harness ${CLICKHOUSE_CURL} --max-time 120; the
   query_duration BETWEEN 1 AND 60 assertions are the real correctness cap.

2. query_log async-commit race. After the (HTTP/TCP) response is returned, the
   terminal query_log row is written to the async buffer and is not necessarily
   committed to the table by the time a single SYSTEM FLUSH LOGS + SELECT runs;
   under flaky-check (50x, high CPU contention) the SELECT occasionally found no
   row and the query_duration line was dropped. Fixed by polling FLUSH LOGS +
   SELECT until the row appears before asserting (same remedy as
   02494_query_cache_http_introspection).

The cancellation-window coverage is preserved for every client path (each query
carries a query_id whose duration is asserted). Assertions unchanged.
@groeneai
groeneai force-pushed the groeneai/fix-flaky-02122-join-group-by-timeout branch from 4cd796c to 91ad9c5 Compare July 7, 2026 11:51
@groeneai

groeneai commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

The flaky-check FAIL on `4cd796c` was the `query_duration` assertion I added for the second HTTP block being itself non-deterministic: after the HTTP response returns, the terminal `query_log` row is written to the async buffer and is not guaranteed to be committed to the table by the time a single `SYSTEM FLUSH LOGS query_log` + `SELECT` runs. Under the flaky-check 50x loop that SELECT occasionally found no row, dropping the `query_duration` line.

Fixed by polling `FLUSH LOGS` + `SELECT` (scoped to the query_id, up to 60 iterations) until the terminal row appears before asserting — the same remedy `02494_query_cache_http_introspection` uses for the identical async-commit race. Applied uniformly to all four assertions (both HTTP paths and both TCP paths) via an `assert_query_duration` helper, so the HTTP cancellation-window coverage you asked for is preserved and deterministic. The curl-truncation fix (inherit the harness 120s cap) is unchanged.

Verified on the debug binary: 30/30 passes; mechanism confirmed (the row is absent from `query_log` immediately after the query returns and only appears after a FLUSH, which the poll loop now always catches). New head: `91ad9c5`.

A max_execution_time=1 cancellation cannot finish before 1000 ms (measured
floor is consistently 1000-1001 ms across TCP and HTTP), so assert
query_duration_ms BETWEEN 1000 AND 60000 directly instead of
round(query_duration_ms/1000) BETWEEN 1 AND 60. The rounding form accepted
durations in (500, 1000) ms (e.g. 999 -> 1), which would hide a too-fast
sub-1s cancellation regression. Output (boolean 1) is unchanged.

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

groeneai commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

Good catch. Tightened in daf1b49: the helper now asserts query_duration_ms BETWEEN 1000 AND 60000 (no rounding) instead of round(query_duration_ms/1000) BETWEEN 1 AND 60.

Measured the actual floor locally (debug build, 25 runs across TCP and HTTP): a max_execution_time=1 cancellation never completes before 1000 ms (observed 1000-1001 ms every run). So an inclusive >= 1000 lower bound is safe and closes the (500, 1000) ms gap where a too-fast sub-1s cancellation would have rounded to 1 and passed. Reference output (boolean 1) is unchanged; test passes deterministically.

@clickhouse-gh

clickhouse-gh Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.04% 86.05% +0.02%
Functions 91.48% 91.48% +0.00%
Branches 78.60% 78.64% +0.04%

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

Newly covered by added/modified tests: 114 line(s), 9 function(s) across 47 file(s) · Details

Top files
  • src/Functions/catboostEvaluate.cpp: 17 line(s), 4 function(s)
  • src/Functions/structureToFormatSchema.cpp: 9 line(s)
  • src/Columns/ColumnObject.cpp: 5 line(s)
  • src/Functions/UserDefined/UserDefinedExecutableFunctionFactory.cpp: 5 line(s)
  • src/Functions/flipCoordinates.cpp: 5 line(s)

Full report

@groeneai

groeneai commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — daf1b49

Our PR touches only tests/queries/0_stateless/02122_join_group_by_timeout.{sh,reference}. None of the failures below are caused by this diff; every one has an owner (a fixing PR or a full-effort tracking task).

Check / test Reason Owner / fixing PR
Stateless tests (arm_binary, parallel) / 04061_spilling_hash_join_overflow_limits flaky (10 master + 15 PRs / 30d, not in our diff) #109334 (ours, open)
Stress test (arm_release) / Not-ready Set (STID 0250-3e49) trunk bug (3 unrelated PRs, 0 master / 30d) #107924 (ours, open)
Stress test (arm_release) / Cannot start clickhouse-server + Check failed collateral of the Not-ready Set logical error above #107924 (ours, open)
CH Inc sync — CH Inc sync (private, not actionable)

The flaky-check FAIL of 02122_join_group_by_timeout on the earlier head 4cd796c was a genuinely PR-caused non-determinism in the query_log duration assertion; it was fixed on head daf1b498 (poll-loop assert_query_duration waiting for the async query_log commit) and no longer fails.

Session id: cron:our-pr-ci-monitor:20260707-170000

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - eeadb5b

CI fully finished on this head (no check queued or in progress, the praktika aggregator
completed, and the CIDB ingestion buffer has elapsed). Zero failing checks on this head,
so there is nothing to own.

Session id: cron:our-pr-ci-monitor:20260729-120000

@alexey-milovidov alexey-milovidov self-assigned this Jul 30, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 30, 2026
Merged via the queue into ClickHouse:master with commit 7f0d0e5 Jul 30, 2026
178 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 30, 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 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.

4 participants