Skip to content

Fix flaky 00377_shard_group_uniq_array_of_string_array under shared-runner memory pressure - #107054

Closed
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-00377-azure-overcommit
Closed

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-00377-azure-overcommit

Conversation

@groeneai

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

00377_shard_group_uniq_array_of_string_array fails intermittently on Stateless tests (arm_asan_ubsan, azure, parallel) with Code: 241 (total) memory limit exceeded.

The failing query is not over its own limit. The server total RSS is already at the host cap (53.68 / 53.69 GiB) from other concurrent queries on the shared azure-parallel runner, and the OvercommitTracker selects this query's AggregatingTransform as the victim to stop. CIDB shows 3 hits in 30 days across 3 unrelated PRs (#106733, #98472, #106808), 0 on master, all on the same azure-parallel check.

The fix bounds the test's thread count (SET max_threads = 4) so its peak memory footprint is lower and it is far less likely to be the OvercommitTracker victim. The tracker picks the victim by overcommit ratio (query memory / soft limit), so a smaller query is less exposed under shared-runner pressure.

Measured locally on a debug build (10M-row Memory table, 4-way remote() fan-out): peak memory of the heavy fan-out query drops from ~1.1-1.3 GiB at the default thread count to ~0.57-0.67 GiB with max_threads = 4 (roughly halved). Output is unchanged and matches the reference exactly.

Same approach and precedent as #106667. Reported by alexey-milovidov on #106733.

…unner memory pressure

The test fails intermittently on Stateless tests (arm_asan_ubsan, azure, parallel)
with Code 241 (total) memory limit exceeded. The failing query is not over its own
limit: the server total RSS is already at the host cap (53.68/53.69 GiB) from other
concurrent queries on the shared azure-parallel runner, and the OvercommitTracker
selects this query's AggregatingTransform as the victim to stop.

Bound the test's thread count so its peak memory footprint is lower and it is far
less likely to be picked as the OvercommitTracker victim. Measured locally on a
debug build with a 10M-row Memory table and a 4-way remote() fan-out: peak memory
of the heavy fan-out query drops from ~1.1-1.3 GiB at default thread count to
~0.57-0.67 GiB with max_threads=4 (roughly halved). Output is unchanged.

Same approach and precedent as PR ClickHouse#106667.

Reported by alexey-milovidov on PR ClickHouse#106733; also seen on unrelated PRs ClickHouse#98472 and ClickHouse#106808.

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

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? Yes. With a 10M-row Memory table and the 4-way remote() fan-out, the heavy groupUniqArray query fails with Code: 241 on demand for any max_memory_usage below its peak: default thread count needs ~1.1-1.3 GiB, so it fails at a 1.1 GiB cap and passes at 1.3 GiB. This is the same per-query memory profile the runner-wide OvercommitTracker arbitrates against.
b Root cause explained? The query is the OvercommitTracker victim, not over its own limit. On arm_asan_ubsan, azure, parallel the server total RSS is already at the host cap (53.68 / 53.69 GiB) from other concurrent queries; the tracker picks the victim by overcommit ratio (query memory / soft limit) and selects this query's AggregatingTransform to stop, surfacing as (total) memory limit exceeded. CIDB: 3 hits / 3 unrelated PRs / 0 master, all on this one azure-parallel check.
c Fix matches root cause? Yes. SET max_threads = 4 lowers this query's own peak memory, which directly lowers its overcommit ratio, so under shared total-RSS pressure it is far less likely to be the selected victim. Not a band-aid: no assertion widened, no data reduced, no no-random-* tag.
d Test intent preserved / new tests added? Preserved. The test still builds the full 10M-row dataset and runs both the local and 4-shard groupUniqArray aggregations; only thread count is bounded. Output is byte-identical (same md5) at 4 vs default threads and matches the existing .reference exactly. No assertion was weakened.
e Both directions demonstrated? Yes. Without the fix (default threads) the heavy fan-out query peaks at ~1.1-1.3 GiB; with max_threads = 4 it peaks at ~0.57-0.67 GiB (roughly halved) while producing identical output. The full test SQL with the fix matches .reference exactly (40 rows of 20001).
f Fix is general, not a narrow patch? N/A (flaky-test setting fix, not a code bug). The change is scoped to the one test that is the OvercommitTracker victim; it does not touch engine code. The general azure-runner memory-pressure problem is tracked separately (e.g. #106055, #104964).

Session id: cron:clickhouse-worker-slot-5:20260610-184028

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Jun 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4120d0c]

Summary: ✅


AI Review

Summary

This PR stabilizes 00377_shard_group_uniq_array_of_string_array by pinning max_threads = 4 before the memory-heavy local and remote groupUniqArray queries. The change is narrowly scoped to the flaky stateless test, preserves the existing data volume and assertions, and matches the documented root cause that the query was being selected by OvercommitTracker under shared runner memory pressure.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.60% 84.60% +0.00%
Functions 92.30% 92.30% +0.00%
Branches 77.20% 77.20% +0.00%

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

Newly covered by added/modified tests: 357 line(s), 12 function(s) across 119 file(s) · Details

Top files
  • src/Storages/StorageReplicatedMergeTree.cpp: 34 line(s)
  • src/Dictionaries/RegExpTreeDictionary.h: 9 line(s), 7 function(s)
  • src/Functions/FunctionsCodingIP.cpp: 9 line(s)
  • src/Functions/multiIf.cpp: 9 line(s)
  • src/Storages/MergeTree/LeaderElection.h: 9 line(s)

Full report

@Algunenano Algunenano self-assigned this Jun 11, 2026

@Algunenano Algunenano 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.

This is the wrong approach and a waste of time. Using 1GB in a query is fine and does not require adjustment A global limit in a CI run should be investigated and analyzed.

@groeneai

Copy link
Copy Markdown
Collaborator Author

@Algunenano you are right, the per-test pin is the wrong approach and I have closed this PR.

I investigated the global limit as you asked. The data confirms this is a single-lane, runner-wide problem, not a 00377 bug:

  • Code 241 (total) memory limit exceeded on Stateless tests (... parallel), 2026-06-09..06-11: 997 rows across 110 PRs on arm_asan_ubsan, azure, parallel, vs 2 rows / 1 PR on every other parallel lane combined.
  • 00377 itself is a victim: 5 failures across 5 unrelated PRs, 0 on master, each query wanting only 1.2-6 GiB while the server total sat at the 53.69 GiB cgroup cap. Lowering its footprint would not have fixed the lane.

The actual hog and the correct fix is yours: #106962, tagging 01603_read_with_backoff_bug no-asan (it inserts ~25M long-string rows and ASan keeps the freed pages mapped, leaving ~50 GiB RSS after the test finishes -> cascading OOM for subsequent parallel tests). The Code-241 volume on that lane is already dropping post-merge (545 rows on 06-10 vs 79 on 06-11). Thanks for the correction.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Closing: superseded by the global fix #106962 (no-asan tag on 01603_read_with_backoff_bug, the actual memory hog), per @Algunenano's review that per-test pins are the wrong approach for runner-wide OOM.

@groeneai groeneai closed this Jun 11, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants