Skip to content

Tear down an integration test's cluster when its module ends, not at session end - #117564

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:integration-module-scoped-cluster-fixtures
Sep 3, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:integration-module-scoped-cluster-fixtures

Conversation

@groeneai

@groeneai groeneai commented Sep 1, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #117412
Related: #113107

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

Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6) still reports Container memory budget exceeded (/docker) with every test in the job passing, on this PR's own base, a master tree that carries #117412. The run cited on #113107 predates it. At 17:35 UTC on 2026-09-01 that one shard is 192 of 197 such rows fleet-wide.

https://github.com/ClickHouse/ClickHouse/actions/runs/33296819525/job/99262785281
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=8627fa22f01595b16121a0d6100ef243475c778c&name_0=MasterCI&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%206%2F6%29

Three test files declare their cluster fixture scope="session" instead of scope="module": test_refreshable_mat_view and test_refreshable_mat_view_replicated, both on this shard, and test_distributed_over_distributed. A leaf pytest file cannot share a fixture, so session scope only defers cluster.shutdown() to the end of the xdist worker's session. Their servers, Keepers, MinIO and proxies stay resident for the rest of the ~105 minute job, holding 12.4-15.2 GiB, 26-37% of the /docker leaf's whole anonymous budget. worker_plan cannot see them: with ncpu: 16 the CPU half binds at 3 workers, so it models 3 * 11 = 33 GiB at any budget. A fixed tax, not a share, so 8 GiB more cap raised the ceiling without reaching demand.

Only 3 of 1120 leaf test files use session scope; in conftest.py it is correct, so the new various_checks.sh check is scoped to test_*/test*.py.

Module and session scope give a fixture the same lifetime across one file's tests, so no coverage is lost. Replaying docker lifecycle events over four consecutive modules, peak concurrent containers drop from 13 across 4 projects to 5 across 1, and each fixed module's last destroy moves from 48-286 s after the next module's first create to 2 s before it. All three modules, 126 tests, gave identical outcomes on the unchanged and changed trees and over 5 repeats.

Not addressed here: the shutdown gdb attach is the second contributor, resident at 70 of 154 kernel OOM snapshots at 4.8-7.7 GiB RSS.


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


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

Version info

  • Merged into: 26.9.1.599 (included in 26.9 and later)

…session end

`Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6)` reports
`Container memory budget exceeded (/docker)` with every test in the job passing,
including on trees that already carry ClickHouse#117412. Of the 196 such rows across all
integration checks on 2026-09-01, 191 are that one shard.

`test_refreshable_mat_view` and `test_refreshable_mat_view_replicated`, both on
that shard, and `test_distributed_over_distributed` declare their cluster fixture
`scope="session"`. A leaf pytest file cannot share a fixture with another file, so
session scope buys nothing while the module runs and only defers
`cluster.shutdown()` to the end of the xdist worker's session. Their ClickHouse
servers, Keepers, MinIO and nginx proxies then stay charged to the `/docker` cgroup
leaf for the rest of the ~105 minute job: 12.4-15.2 GiB, 26-37% of that leaf's
entire anonymous budget, held by modules that have finished.

`worker_plan` cannot account for them. With `ncpu: 16` the `cpus // 5` half binds
at 3 workers, so the plan models `3 * 11 = 33 GiB` regardless of the budget, which
is why raising the leaf cap from 40.78 to 48.78 GiB moved the ceiling without
getting above demand: the leak is a fixed tax, not a share.

Module and session scope give a fixture the same lifetime across one file's tests,
so this changes no assertion. Measured by replaying docker lifecycle events over
four modules run back to back: peak concurrent containers drop from 13 across 4
compose projects to 5 across 1, and each fixed module's last `destroy` moves from
48-286 s after the next module's first `create` to 2 s before it. Running all three
modules in full gave the same 126 test outcomes on the unchanged and the changed
tree, and over 5 repeats.

These are the only 3 of 1120 leaf integration test files that use session scope. In
`tests/integration/conftest.py` it is correct, so the new check in
`various_checks.sh` is scoped to `test_*/test*.py`; it reports 3 files before this
change, 0 after, and exactly 1 when session scope is restored in one file.

The shutdown `gdb` attach is a second contributor and is not addressed here.

Related: ClickHouse#117412

Co-Authored-By: Claude Opus 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 Sep 1, 2026
@groeneai

groeneai commented Sep 1, 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; 1 finding) plus my own cold
review of the resulting tree (4 findings). Two full gate passes, no fix round: the second pass
re-read the PR description after I revised it, and returned 0 findings.

# Sev Finding Verdict Evidence / action
1 ⚠️ The description did not link the thread that requested this PR, and omitted the CI report URL provided there AGREE, fixed before publication AGENTS.md asks for both, one relationship per line. Added Related: for #113107 and the job URL. The cited run is on 66242ce6fbda, which carries the pre-#117412 INTEGRATION_DIND_INIT_RESERVE = min(max(LIMITED_MEM // 3, ...)), so it does predate the fix, verified by content rather than by date
2 💡 Container memory budget count in the description was a live counter that would stop reproducing AGREE, fixed before publication Re-measured: 192 of 197 rows at 17:35 UTC on 2026-09-01, and the instant is now stated so the claim stays true
3 💡 "today" is a relative time (raised by the gate) AGREE, fixed before publication AGENTS.md:184 "Never use the relative time", in the tree since 2026-03-02, so it binds this branch. Replaced with the absolute date
4 💡 The description compared gdb RSS against a figure its source comment states as anonymous memory only AGREE, fixed before publication integration-tests-entrypoint.sh:34 models "3.4 GiB of anonymous memory" while the memcg also charges mapped file pages. Comparison dropped, the disclosure kept
5 💡 The new check's --include='test*.py' does not cover tests/integration/test_*/conftest.py AGREE, documented not fixed 0 of those 7 files, and 0 files of any type under test_*/, currently declare session scope, so the check is exact for this tree; --include='conftest.py' would extend it with no false positive, since the legitimately session-scoped tests/integration/conftest.py is outside the grep roots by path

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.

Independently verified while reviewing, and clean: no session-scoped consumer of the three
started_cluster fixtures exists, so narrowing the provider raises no scope error, and ordering is
still forced by module_setup_tables requesting it explicitly; an earlier cluster.shutdown()
cannot disturb a concurrent cluster, because get_running_containers filters on the anchored
^/{project_name}-.*-1$ and the network sweep on the project name, neither of which can match the
sibling project; the number of cluster.start() calls is unchanged under --dist=loadfile,
--dist=each and --count N --random-order, since all three keep a module's items contiguous; the
check is byte-silent on both streams when clean, which is what check_style.py check_other()
requires, and reports exactly the 3 files when the change is reverted; and these three modules are
green over 14 days of CIDB, so moving the fatal and sanitizer log scans to module teardown cannot
turn a passing module red.

Session id: cron:clickhouse-review-slot-10:20260901-172800

@clickhouse-gh clickhouse-gh Bot closed this Sep 1, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 1, 2026
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Sep 1, 2026
@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Not a rate: a fixture-lifetime property read off docker's own create/destroy events while one xdist worker runs four modules back to back. Every module's containers are asserted to appear first, so no assertion can pass vacuously.
b Root cause explained? Yes. A leaf pytest file cannot share a fixture, so scope="session" only defers cluster.shutdown() to the end of the worker's session. The finished module's servers, Keepers, MinIO and proxies stay charged to the /docker cgroup leaf for the rest of the job, and worker_plan sizes concurrency without them: at ncpu: 16 the CPU half binds at 3 workers, so it models 3 * 11 = 33 GiB whatever the budget is.
c Fix matches root cause? Yes. The fixture gets the lifetime it needs, so the containers are released when the module ends. No widened bound, no no-parallel, no smaller dataset, no capacity lever, no guard at the kill site.
d Test intent preserved / new tests added? Yes. Module and session scope give a fixture the same lifetime across one file's tests, so no assertion changes: 126 test outcomes identical before and after. The regression guard is the new various_checks.sh check, and it is validated to count, not just to fire.
e Both directions demonstrated? Yes. With session scope all three modules survive into the next module (-285.8 s, -101.6 s, -48.6 s); with module scope all three are gone before it (+2.0 s, +2.1 s, +2.1 s). Peak concurrent containers 13 across 4 compose projects, down to 5 across 1.
f Fix is general across code paths? Yes. All 1120 leaf integration test files enumerated: exactly 3 use session scope and all 3 are fixed, including test_distributed_over_distributed, which is not on the failing shard. conftest.py, where session scope is correct, is deliberately untouched.
g Fix generalizes across inputs (params/datatypes/wrappers)? No type or settings matrix applies (no C++, no settings, no user input). The applicable axes are covered: the check matches both quote spellings, and both fixture forms present in these files ((scope=..., autouse=True) and bare (scope=...)).
h Backward compatible? (maintainer-approved exception only) N/A, vacuously. No settings, no SettingsChangesHistory.cpp, no serialization format, no experimental gate, no user-visible behaviour.
i Invariants and contracts preserved? Yes. pytest's rule that a fixture may not depend on a narrower-scoped one still holds: the only consumers are module_setup_tables (module), fn_setup_tables / fn3_setup_tables (function) and test functions, and both arms collected and ran. cluster.shutdown() still runs exactly once per module in its finally: block, only earlier. various_checks.sh stays byte-silent when clean, which is what check_other() requires.

Session id: cron:clickhouse-impl-slot-6:20260901-161100

@clickhouse-gh

clickhouse-gh Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [72c4b21]

Summary: ✅


AI Review

Summary

This PR narrows three module-local integration-test cluster fixtures from scope="session" to scope="module" and adds a style check to prevent that specific lifetime bug from being reintroduced in leaf tests/integration/test_* files. Static review of the touched code did not find a correctness, safety, or test-contract issue in the current diff.

Missing context / blind spots
  • ⚠️ I did not execute the affected integration tests locally because pytest is not installed in this environment; the remaining runtime validation is the pending CI for commit 72c4b2191030f9034bdcedae02ecbb06803d39b0.
Final Verdict

✅ No review findings in the current diff.

@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

cc @maxknv, could you review this? Three integration test files declare their cluster fixture scope="session", which on a leaf pytest file only defers cluster.shutdown() to the end of the xdist worker's session, so their servers and proxies stay charged to the /docker cgroup leaf for the rest of the job and trip the container memory budget guard.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 3, 2026
Merged via the queue into ClickHouse:master with commit 54b113d Sep 3, 2026
344 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 3, 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 groeneai-origin-request PR origin: a maintainer pinged or directed groeneai manual approve Manual approve required to run CI 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