Repository navigation
Bound the integration tests' nested containers by the job's memory limit - #112984
alexey-milovidov merged 4 commits into
Conversation
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent reviewer plus an independent second-model gate, run
Severity: 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding. Session id: cron:clickhouse-review-slot-9:20260802-060300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20260802-030900 |
|
cc @Felixoid @fedotovalexei, could you review this? Integration jobs run a nested Docker daemon under |
|
Workflow [PR], commit [18428a0] Summary: ✅ AI ReviewSummaryThis PR moves the integration-test job family onto cgroup-contained nested Docker, derives worker concurrency from the nested-container budget, adds synthetic OOM reporting/diagnostics, and bounds the image pre-pull path. The current head fixes many earlier review issues, but I do not think it is ready to merge yet: part of the new containment contract can still regress without scheduling the relevant jobs, Findings
Tests
Final VerdictNeeds changes before merge. LLVM Coverage Report |
|
CI on this PR is red in a way that refutes the change, so I am reporting that rather than All six The runners boot with cgroup v1. From the job's
This is why the block I re-enabled was left commented out in My local measurements could not have caught this. They were taken on a cgroup v2 machine, and 45 jobs carry the containment environment (43 Two questions, because I would rather ask than guess:
What I will not do is make the precondition fail open. The PR promises that the nested @clickhouse-gh[bot]'s finding on |
CI finish ledger — 0c997e9All 174 checks completed: 11 success, 157 skipped, 6 failure. Every failure is PR-caused and
The 45 jobs carrying the containment environment (43 |
cgroup v1 rewrite done, and the refusal is goneTaking the fork back per #113719 (comment): Verified on an actual cgroup-v1 kernel, not the fake tree. That matters here: the unit suite
With production's own container flags ( The daemon stayed alive and serving. A 300 MiB control in the same limited container reaches its One asymmetry worth flagging rather than burying. Enforcement ports and gets simpler, but Also in this push: the harness now moves into the capped The review comment about the regression suite reading live host memory is fixed in the same push Session id: cron:clickhouse-maint-slot-13:20260809-024502 |
| # a sibling of this cgroup, so `--memory` bounds only the harness. Explicit because the | ||
| # daemon default is configurable and `host` would silently restore that leak. | ||
| run_in_docker=f"clickhouse/integration-tests-runner+root+--memory={LIMITED_MEM}+--privileged+--dns-search='.'+--security-opt seccomp=unconfined+--cap-add=SYS_PTRACE+{docker_sock_mount}+--volume=clickhouse_integration_tests_volume:/var/lib/docker+--cgroupns=private+--ulimit nofile=262144:262144{integration_dind_env}", | ||
| post_hooks=[ |
There was a problem hiding this comment.
This change moves a critical part of the containment contract into common_integration_test_job_config.run_in_docker, but the integration job still does not treat ci/defs/job_configs.py as an affecting path. Right now:
common_integration_test_job_config.is_affected_by(["ci/defs/job_configs.py"])
# FalseSo a future config-only regression here, such as dropping --cgroupns=private or one of the CI_DIND_* envs, will skip the end-to-end integration shards entirely. Please add ./ci/defs/job_configs.py to this job's digest_config.include_paths.
There was a problem hiding this comment.
Your is_affected_by measurement is correct: common_integration_test_job_config.is_affected_by(["ci/defs/job_configs.py"])
is False, with ci/jobs/integration_test_job.py, ci/jobs/scripts/docker_in_docker.sh and
tests/integration/ all returning True as controls. I am not making the change, for two
measured reasons.
The regressions you name are already caught. JobConfigs.ci_tests has ./ci in its
include_paths, so ci_tests.is_affected_by(["ci/defs/job_configs.py"]) is True, and
ci_tests_job.py runs pytest ci/tests/. Two of those tests pin this contract, so I mutated
the file to check they are not vacuous:
- deleting
+--cgroupns=privatefailstest_job_requests_a_private_cgroup_namespace - deleting the
CI_DIND_NESTED_BUDGETenv failstest_job_passes_the_budget_and_reserves_to_the_script
Both mutants were killed, and the tree was restored and re-verified green after each. A
config-only regression therefore reddens CI Tests, not silently nothing.
The cost is also concrete. ci/defs/job_configs.py took 88 commits in the last 30 days, and
every one of those touched no path currently in this job's include_paths, so the change would
newly trigger the full six-shard integration matrix 88 times a month, on this specific family.
That is the family the parent PR exists to stop wedging its runners.
Convention agrees: of 220 job configs, 210 have non-empty include_paths and 0 include
ci/defs/job_configs.py. CI Tests is where config-shape regressions are meant to land, and it
covers this one.
58b0a8d to
e24d46c
Compare
|
Pushed a fix for the The failure. Shards 4/6 and 5/6 of run 31299101298 reported Cause. The 8 GiB One correction to my own earlier note. I first put the demand at 12-15 GiB by summing the kernel's OOM task dump. That is wrong: on cgroup v1 the dump enumerates the whole hierarchy, not the breached cgroup. The cgroup-scoped figure is Also fixed, each with a mutation-verified test:
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline. |
| _SHELL_INT_MAX = 2**63 - 1 | ||
|
|
||
|
|
||
| def nested_budget_gb(env=None, physical_memory=None) -> int: |
There was a problem hiding this comment.
After 3f8ebf8 dropped the dedicated ci/tests/test_integration_memory_limit.py arm, there is no focused regression coverage left for this whole CI_DIND_* path. I checked the current ci/tests/ tree and there are no remaining references to CI_DIND_*, leaf_oom_report, job_cgroup_oom, dind_unreportable_ooms, or the containment shell block; the surviving tests only cover adjacent helpers like the outer image-pull retry path and timeout plumbing.
That leaves the v1/v2 cgroup parsing, worker-budget wiring, and synthetic OOM/job-cgroup reporting to be validated only by the full integration matrix, which is exactly the kind of coverage gap that let several earlier regressions on this PR survive until they hit real shards. Please keep a focused regression suite for this contract before merging.
There was a problem hiding this comment.
Confirmed, and already disclosed in #112984 (comment) at 03:00Z, 71 minutes before this comment: at 18428a05 there are 0 references under ci/tests/ to CI_DIND_, leaf_oom_report, job_cgroup_oom or dind_unreportable_ooms.
The causal premise does not hold, though. That arm ran on 6 heads of this PR between 08-15 and 08-25: 328 cases at the last of them, 1768 case executions, 0 failures. The defect the previous round here found (the archive block keyed on failed_suits, with the synthetic rows appended after the relabel) was present in all six of those heads and the arm passed on every one; the only red CI Tests rows on this PR come from ci/tests/test_settings_history_source_gate.py, a different file.
I am not restoring it, because there will be nothing left to run it. #114675 merged on 08-15 (+0/-6543, 32 files, all under ci/tests/), and #115650 removes the rest of the directory (64 files on master today) together with the only executor: ci/jobs/ci_tests_job.py, plus JobNames.CI_TESTS, the ci_tests job config and its entry in .github/workflows/pull_request.yml. Nothing else in the tree runs pytest over ci/ python; tests/ci has no test files and is mypy-only, ci/praktika has none. #115650 is still open as of this comment, last synced with master at 01:41Z today.
The gap is narrower than the whole CI_DIND_* path. The containment block is fail-closed at 18 refusal sites in docker_in_docker.sh and runs in all 35 integration job instances of the PR workflow, so a regression in the env contract, the v1-vs-v2 detection, the private-namespace check or the budget arithmetic turns those jobs red. What is only exercised is the reporting side: leaf_oom_report and job_cgroup_oom execute when a leaf actually breaches, so a regression there stays silent until one does, and by that function's own contract a killed run could then finish green.
If a home for a focused suite survives #115650, name it and I will add a small one for that reporting side; those helpers take env and cgroup_root arguments, so they need no docker.
`docker compose stop` signals every container of a cluster at once, so every node whose server outlives the entrypoint's 60 second deadline attaches gdb at the same moment. gdb has to read the whole binary's debug info to walk the stacks, measured at 3.4 GiB of anonymous memory on an ASan build and 4.3 GiB on the coverage one, so a nine node cluster asks for around 40 GiB - the entire budget `docker_in_docker.sh` gives the cgroup that holds the nested containers. The kernel kills the gdb processes and the job reports `Container memory budget exceeded (/docker)` with no stacktrace to show for it: on 2026-08-30 that failed `Integration tests (amd_llvm_coverage, 4/8)` four times and `Integration tests (amd_asan_ubsan, flaky)` once, every time with 8 to 10 gdb processes alive at the instant of the kill and every test in the batch otherwise green. The attach is now taken under a lock on the repository mount, the only path every ClickHouse container of every pytest worker shares, so the job as a whole holds one gdb at a time instead of one per node. The pid is re-checked once the lock is held, which is what keeps the common case free: a server that was merely slow rather than stuck exits while its turn is waited for, and then there is nothing to attach to. A node that does not get its turn within 240s says so and is skipped, because the wait has to leave room inside the container's 10 minute `stop_grace_period` for the deadline and for gdb itself. The `/docker` cap that turns this pre-existing overrun into a reported failure arrived with the pull request below; before it the nested containers were charged outside the job's memory limit. Related: ClickHouse#112984 https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=f14f29dd31bbb4861b7c9a4d47cd65750145d8a0&name_0=MasterCI&name_1=Integration%20tests%20%28amd_llvm_coverage%2C%204%2F8%29
…y use `docker_in_docker.sh` splits the integration job's memory limit into three capped cgroup leaves, and `/docker` - the one that parents every nested test container - is sized last, from whatever the other reserves leave. On the 61.78 GiB runner that is 40.78 GiB, and it is not enough: over 58 job runs `/docker` peaked at exactly its cap in all 58, so the kernel is picking a victim whenever anything asks for more. The job then reports `Container memory budget exceeded (/docker)` while every test in the batch passes - 15 of the 26 master runs of `Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6)` after 2026-08-31 12:00, and before that shards 2/6 and 5/6 as well. The sizing rests on an assumption the kernel's own OOM report refutes. It gives `/init` a third of the job limit and `/docker` the remainder, on the grounds that `/init`'s charge is anonymous while `/docker` holds page cache reclaim can give back. Measured at the kill, `/docker` holds 40.35 GiB of anonymous memory against 753664 bytes of cache - not one page of it is reclaimable. `/init` and `/dockerd` are the ones running on cache: they peak at 20.8 GiB and 18.3 GiB against reserves of 16 GiB and 2 GiB, 20 GiB above what the partition promises them, and the job cgroup still never breaches, because reclaim takes that back. The only leaf that cannot give anything back is the one being sized last. So `/init` keeps the floor instead of the share, and `/docker` gets the 8 GiB that frees: 48.78 GiB against a measured peak of 40.35 GiB of servers plus the 3.4 to 4.3 GiB a shutdown `gdb` attach adds on top of them. `/init`'s own ceiling is unchanged - the reserve was never its cap - so this takes away none of the room it uses. Worker concurrency is unchanged too: the plan derived from the budget stays at 3 workers (and 2 under `--dist=each`), so no job runs longer for this. This is the remainder of the same overrun ClickHouse#117202 addressed. Serializing the shutdown `gdb` attaches removed the 4-at-once pile-up and fixed shards 2/6 and 5/6, but in 6/6 the servers alone reach 39.30 GiB across 34 processes, so a single 4 GiB attach no longer fits either - and half the kills there have no `gdb` in them at all. Related: ClickHouse#117202 Related: ClickHouse#112984 https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=25dfbdb6c5dd3c0bd78c7134c14045ddb7647bcf&name_0=MasterCI&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%206%2F6%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Integration test jobs now charge their nested Docker containers to a cgroup bounded by the job's own
--memorylimit, instead of a cgroup outside it.Description
Related: #112625
The bug. Under
--cgroupns=hostdockerd parents the nested containers at the host's/docker,a sibling of the job's cgroup, so they are charged outside the job's
--memorylimit. Measured: alimited child overran its cap with the job's cgroup at
oom_kill 0.The fix. The job asks for
--cgroupns=private, making its own cgroup the namespace root;docker_in_docker.shcaps three leaves there (/init,/dockerd,/docker) and refuses to startthe daemon rather than run uncontained.
/initis capped by the joblimit less the leaves it does not overlap: its share alone killed two shards of this branch's CI, in
bursts of ~50-60 host-side clients, while four identical shards passed at 11.5-12.5 GiB. The caps
therefore no longer partition the job limit, so a breach of the job's own cgroup is reported too:
neither a leaf nor a host OOM, it had no owner.
Hard-timeout diagnosability. A run the backstop kills is past its budget, so the runner cancels it
mid-archive and nothing is uploaded: on job 95139621296 the archive got 13.3 s, and every diagnostic
sat behind it, which is why that wedge could not be attributed. The counters and the
dmesgdump werealready collected, so only their order was wrong; they now print to stdout, the one channel a
cancelled job keeps, ahead of the archive. No row is derived from that buffer, which is neither
cleared nor scoped there. Only the hard backstop counts, as the graceful session-timeout leaves hours
of the job deadline. The archive is bounded there so a stuck one cannot reach that deadline, sized to
finish an ordinary archive rather than to fit the cancellation window, as no bound does both.
Behavior change.
--dist=eachdrops from 3 workers to 2, concurrency now deriving from thenested budget rather than host memory.
Validation detail
Every arm runs the real script in the runner image with children that request resource limits
(
mem_limit: 12g,cpus: 5,pids_limit: 5000, ashelpers/cluster.pyapplies); a limit-lesschild cannot discriminate. The v1 arms run on a cgroup-v1 kernel booted with the runners' own
cmdline, since the unit fixture always has
cgroup.controllersand so cannot see a v1 host.Client.queryforks one host-side client per concurrent query, which is what those bursts are, andboth killed shards died with the aggregate still inside the job limit.
/init's charge is anon, sounlike
/dockerreclaim cannot meet its cap. On v1 the leaves cap swap as well. The worker count is40 GiB of nested budget on the 59.8 GiB carrier, against the 60 GiB that 3 workers budgeted.
oom_kill 0oom_memcg=.../docker,CONSTRAINT_NONEcount 0, daemon alive/initdocker runanddocker composeboth rc=0/init; other leaves clean; daemon alivedmesg, including a nested-container victim on v1Workflow [PR]
Sync PR [sync-upstream/pr/112984]
Version info
26.9.1.334(included in26.9and later)