Skip to content

Fix flaky 02357_query_cancellation_race - #119716

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-02357-cancellation-race-read-limit
Sep 13, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-02357-cancellation-race-read-limit

Conversation

@groeneai

@groeneai groeneai commented Sep 13, 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):

Fixed flaky test 02357_query_cancellation_race, which could fail when the stateless CI read limit aborted its intentionally unbounded insert and the resulting error reached the test's stderr.

Description

The test runs 100 iterations of an unbounded insert into tab select number, toString(number) from system.numbers, each stopped by a 0.05s SIGINT. || true swallows the exit code, so stderr is the test's only failure channel.

The stateless CI profile puts a finite read limit on that unbounded read: tests/config/users.d/limits.yaml sets max_rows_to_read = 20000000. An iteration that outlives its signal keeps reading, ReadProgressCallback::onProgress calls SizeLimits::check, and TOO_MANY_ROWS is logged at <Error>. Because $CLICKHOUSE_CLIENT always carries --send_logs_level=warning, that line is streamed onto the test's stderr, and clickhouse-test fails any test whose stderr is non-empty. The test asserts nothing about read limits, so this is exposure, not a product defect.

I pin max_rows_to_read = 0, max_bytes_to_read = 0 on that insert, so only the cancellation under test can end it. Both are checked by the same SizeLimits::check call, so pinning one would establish half the invariant. This is the existing idiom for cancellation tests over an unbounded system.numbers read (04003_cancel_scalar_subquery.sh, 04051_cancel_parallel_with.sh, 04052_local_cancel_scalar_subquery.sh); 02357 was the only one missing it. The oracle is not weakened: <Fatal> lines, crashes, logical errors and every other server exception still reach stderr and still fail the test.

Validation, at the profile's real 20000000 with the window widened to 3s to force the race: 3/3 runs fail without this change (read_rows 20015154, Code: 158), 0/3 with it. system.query_log then records Settings['max_rows_to_read'] = 0 and 87844287 rows read, 4.4x past the limit. Unmodified test, randomization on: 50/50 pass, p50 6.77s against 6.80s before.

CI provenance, the first failure of this test in the retained window: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=119687&sha=5ad83a88e1eda5773c9e00c0a9c6ab7dbfe17f1a&name_0=PR

CIDB: every failure of this test in 90 days (query and result)
SELECT check_start_time, pull_request_number AS pr, check_name, test_status
FROM default.checks
WHERE test_name = '02357_query_cancellation_race' AND test_status IN ('FAIL','ERROR')
  AND check_start_time > now() - INTERVAL 90 DAY
ORDER BY check_start_time
┌────check_start_time─┬─────pr─┬─check_name───────────────────────────────────────────────────┬─test_status─┐
│ 2026-07-15 10:11:27 │ 110222 │ Stateless tests (amd_asan_ubsan, distributed plan, parallel) │ FAIL        │
│ 2026-07-15 11:56:59 │ 109920 │ Stateless tests (amd_asan_ubsan, distributed plan, parallel) │ FAIL        │
│ 2026-09-12 22:04:43 │ 119687 │ Stateless tests (amd_debug, parallel)                        │ FAIL        │
└─────────────────────┴────────┴──────────────────────────────────────────────────────────────┴─────────────┘

Against 207,700 OK rows over the same window. The two 2026-07-15 rows are a different class and are
not addressed here: both are (total) memory limit exceeded ... current RSS 41.85 GiB, maximum 41.84 GiB,
box-wide pressure that failed 90 and 62 tests respectively in those same two jobs. The 2026-09-12
failure is the one this fixes; it was 1 failure against 13,894 OK in its own job.


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

The test runs 100 iterations of an unbounded
`insert into tab select number, toString(number) from system.numbers`,
each stopped only by a 0.05s SIGINT. `|| true` swallows the exit code, so
stderr is the test's only failure channel.

The stateless CI profile puts a finite read limit on that unbounded read:
tests/config/users.d/limits.yaml sets max_rows_to_read = 20000000 (and
max_bytes_to_read = 1T) on profile `default`. An iteration that outlives its
signal keeps reading; at block granularity ReadProgressCallback::onProgress
calls SizeLimits::check and throws TOO_MANY_ROWS, which executeQuery logs at
<Error>. Because $CLICKHOUSE_CLIENT always carries --send_logs_level=warning,
that log line is streamed to the client and written to the test's stderr, and
tests/clickhouse-test fails any test whose stderr is non-empty.

Pin max_rows_to_read = 0, max_bytes_to_read = 0 on that insert so only the
cancellation under test can end it. Both settings are consulted by the same
SizeLimits::check call, so pinning one alone would establish half the
invariant. This is the existing idiom for cancellation tests over an
unbounded system.numbers read (04003_cancel_scalar_subquery.sh,
04051_cancel_parallel_with.sh, 04052_local_cancel_scalar_subquery.sh);
02357 was the only such test missing it.

The oracle is not weakened: <Fatal> lines, crashes, logical errors and every
other server exception still reach stderr and still fail the test.

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect labels Sep 13, 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), plus my own cold review of
the resulting tree (3 nits). Bounded: 1 full pass + 1 fix round + 1 delta recheck.

# Sev Finding Verdict Evidence / action
1 ⚠️ The modified test does not deterministically require the new read-limit overrides: at the 0.05s window every insert normally dies before 20M rows, so reverting the two settings, or the server silently ignoring them, would still leave stderr empty. Remedy asked for: a deterministic in-test probe with tiny row and byte limits. DISAGREE The "silently ignoring" half is disproved by measurement: the pinned query reads 87,844,287 rows, 4.4x past the 20000000 profile limit, with zero TOO_MANY_ROWS, while the byte-identical unpinned arm throws at 20,015,154 rows in 300/300 insert queries, and system.query_log records Settings['max_rows_to_read'] = 0 with the key present in both arms, so nothing rests on absence. The revert direction does redden once the window is widened to 3s to force the race: 3/3 runs fail at the profile's real 20000000, 5/5 at a forced 100000, 3/3 with the limit supplied as a client argument, against 0/3, 0/5 and 0/3 pinned. The residual point, that the unmodified 0.05s loop usually passes without the fix, is the definition of the flakiness being repaired here (1 failure against 58,907 passes in 30 days). I declined the in-test probe: it would turn an existing regression test for #39132 into a self-test of per-query settings overrides, a property more than 120 stateless tests already exercise, and asserting on "the client needed SIGKILL" would make this test more flaky rather than less.
2 💡 The precedent list omits 02697_stop_reading_on_first_cancel.sh, which pins the same limit over an unbounded system.numbers read cancelled by SIGINT, in argv form. AGREE, noted Added to the pre-PR validation gate comment. Left out of the PR body, which is already at its concision budget.
3 💡 Removing the incidental TOO_MANY_ROWS abort lets a lost-cancellation iteration run on to the --kill-after=5 SIGKILL instead, reading about 4.4x more rows. AGREE, noted Checked, and it does not widen the duration envelope: --kill-after=5 already dominated the row bound, so the 100-iteration worst case is 505s against the runner's 600s per-test timeout, identical before and after this change. Measured p50 6.77s pinned against 6.80s unpinned over 50 randomized runs each. GNU timeout prints nothing when it kills a child, so that path contributes no stderr of its own.

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

Session id: cron:clickhouse-review-slot-9:20260913-010300

@clickhouse-gh clickhouse-gh Bot closed this Sep 13, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 13, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. At the profile's real max_rows_to_read = 20000000, with the cancellation window widened from 0.05s to 3s so the query outlives its signal on demand: 3/3 runs fail. With the limit forced to 100000 instead: 5/5 fail, with byte-identical stderr (485,100 B) every run.
b Root cause explained? Yes. tests/config/users.d/limits.yaml puts max_rows_to_read = 20000000 on the stateless profile; the test's system.numbers read is unbounded by design and stopped only by a 0.05s SIGINT. An iteration that outlives its signal keeps reading, ReadProgressCallback::onProgress calls SizeLimits::check, TOO_MANY_ROWS is logged at <Error>, --send_logs_level=warning streams that line onto the test's stderr, and clickhouse-test fails any test whose stderr is non-empty. || true makes stderr the test's only failure channel.
c Fix matches root cause? Yes. The two limits that SizeLimits::check actually consults are pinned off on that one query. No widened bound, no no-random-* tag, no data-size reduction, no stderr filtering, no change to the cancellation path.
d Test intent preserved / new tests added? Preserved. This repairs an existing regression test (for #39132, 37f0d96e36f03), so no new test is added. Only the read-limit class is removed from the oracle: <Fatal> lines, crashes, logical errors and every other server exception still reach stderr and still fail the test. timeout -s 2 --kill-after=5 0.05 and --interactive_delay 1000 are unchanged.
e Both directions demonstrated? Yes. Profile at the real 20000000: 3/3 fail without the change, 0/3 with it. Profile forced to 100000: 5/5 without, 0/5 with. Limit supplied as a client argument instead (how randomized settings arrive): 3/3 without, 0/3 with. All on a Build-ID-asserted server.
f Fix is general across code paths? Yes. Restricting the census to cancellation tests over an unbounded source (system.numbers / numbers_mt()) leaves five: 04003_cancel_scalar_subquery.sh, 04051_cancel_parallel_with.sh and 04052_local_cancel_scalar_subquery.sh already pin this exact pair; 02697_stop_reading_on_first_cancel.sh and 00600_replace_running_query.sh pin the rows limit in argv form (--max_rows_to_read 0). 02357 was the only one missing a pin, so no sibling is left unfixed. Related prior art on a bounded-but-huge source: 04410_primes_source_cancellation.sh, 04028_kill_query_expression_cancelled.sh.
g Fix generalizes across inputs? Test-only change, so there is no input surface. I enumerated the invariant's carriers and pinned both finite ones: max_rows_to_read and max_bytes_to_read are checked by the same SizeLimits::check call, so pinning one alone would establish half the invariant. The *_leaf limits do not apply to this local read, and the remaining profile limits are unreachable inside an iteration's 5.05s lifetime.
h Backward compatible? N/A. Test-only, no src/ change, no setting default changed, so no SettingsChangesHistory.cpp entry is due. 0 is the product default for both settings, so the query is still the one a user runs.
i Invariants and contracts preserved? Yes. The invariant asserted is that in this test only the SIGINT may end the insert. A query-level SETTINGS clause is the narrowest carrier that holds it against both a profile value and client-level injection, and I verified both empirically rather than by reading precedence rules. system.query_log records Settings['max_rows_to_read'] = 0 with 87,844,287 rows read, 4.4x past the profile limit, confirming the clause reached the server. No constraints exist on these settings for this user.

Session id: cron:clickhouse-impl-slot-5:20260912-232300

@clickhouse-gh

clickhouse-gh Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d02cef1]

Summary: ✅


AI Review

Summary

This PR narrows 02357_query_cancellation_race.sh so the unbounded INSERT ... SELECT can fail only through the cancellation path under test, not through the stateless profile's read limits leaking TOO_MANY_ROWS into stderr. I did not find a remaining correctness or coverage issue in the current diff; the change matches the existing pattern in comparable cancellation tests, and the PR metadata is appropriate for a CI-only fix.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 13, 2026
@groeneai
groeneai requested a review from davenger September 13, 2026 01:30
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Sep 13, 2026
@alexey-milovidov alexey-milovidov self-assigned this Sep 13, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 13, 2026
Merged via the queue into ClickHouse:master with commit 393a7cc Sep 13, 2026
176 of 348 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 Sep 13, 2026
@clickhouse-gh clickhouse-gh Bot added comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. 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-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect 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