Repository navigation
Reclaim the orphaned buildkit cache volume in the docker clean up hook - #117168
Merged
Merged
Conversation
`Install packages (amd_release)` failed on master with
cannot copy extracted data for './usr/lib/debug/usr/bin/clickhouse.debug' to
'/usr/lib/debug/usr/bin/clickhouse.debug.dpkg-new': failed to write (No space left on device)
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=31f27d85ed6a30aa33cb37f57d4610362ab8bfa1&name_0=MasterCI&name_1=Install%20packages%20%28amd_release%29
The host handed the job 4.3 GiB of 58 GiB, and the very first test needs about
5 GiB. Nothing the job does explains the other 54 GiB: the clean up hook that
runs right before it reported `Total reclaimed space: 0B` for both
`docker container prune` and `docker system prune`, and only two images were
present.
The accumulator is a `docker-container` buildx builder's cache. It lives in a
named `buildx_buildkit_<node>_state` volume, and none of the commands in the
hook reclaim a volume: `docker system prune` skips volumes without `--volumes`,
and `docker builder prune` talks to the daemon, so it only reclaims the cache of
the `docker` driver builder - which is why it reports `0B` on a host that has
just built multi-platform images. The hook does prune per builder, but the
runner removes every container between jobs, so by the time the next job starts
the builder has no buildkit container and the prune fails with
`No such container: buildx_buildkit_default-builder0` - visible in the log of
the failing job - leaving the cache unreachable and on disk. The host had run
`Docker server image` and three `Docker keeper image` jobs beforehand, each
writing gigabytes into that volume; `Docker server image` alone took the host
from 24 GiB to 35 GiB used.
Drop such a builder and remove the volume it leaves behind. `--all-inactive`
keeps a builder whose container is still up, and `docker volume rm` refuses a
volume attached to a running container, so a cache that is still reachable is
pruned by the existing per-builder prune rather than thrown away here. This
mirrors what `_clean_buildx_volumes` in `ci/praktika/native_jobs.py` already
does after the native docker build jobs.
Also print `docker system df`, because the job that runs out of disk space is
rarely the job that filled it, and `Local Volumes` is the row the prunes cannot
reclaim.
Validated locally against docker 29.1.3 / buildx 0.30.1: a 400 MiB build through
a `docker-container` builder leaves a 934 MiB volume that survives
`docker buildx prune --builder`, `docker builder prune -a -f` and
`docker system prune -f` once its container is removed - reproducing the CI
error text exactly - and is reclaimed by the two added commands, while a builder
whose container is still running keeps both its entry and its volume.
The previous commit on this branch carried a truncated tree that dropped every file outside `.github`, `ci` and `docs`. Restore the tree to `master` and keep only the intended change to `ci/jobs/scripts/job_hooks/docker_clean_up_hook.py`.
Contributor
|
Workflow [PR], commit [a05b89d] Summary: ✅ AI ReviewSummaryThis PR changes the docker clean up hook to bootstrap inactive buildx builders before pruning them, then remove only Tests
Final Verdict✅ No remaining review findings on the current head. |
The review points out that `docker buildx rm --all-inactive --force` is broader than reclaiming an orphaned cache: on a stock runner the pre-provisioned `default-builder` is usually just `inactive`, not unrecoverable, and removing it makes a later bare `docker buildx build` fall back to the implicit `default` docker driver, besides throwing away a cache that could have been reused. Reclaim the space without touching the builder entry: bootstrap each builder before pruning it, so an `inactive` `docker-container` builder gets its buildkit container back, the prune reaches the cache and empties the `buildx_buildkit_<node>_state` volume in place, and the builder stays registered for the docker image jobs that expect it. Only a volume whose node belongs to no registered builder is removed - that one is unreachable by any prune. `docker volume rm` additionally refuses a volume attached to a running container. Validated locally against docker 29.1.3 / buildx 0.30.1: a 400 MiB build through a `docker-container` builder whose container is then removed leaves a 534 MiB volume and reproduces the CI error text `ERROR: Error response from daemon: No such container: buildx_buildkit_orphantest0`; `docker buildx inspect <name> --bootstrap` takes 5.6 s, the following prune reclaims 558.7 MB, the volume drops to 352 KiB and the builder is still listed. A stray `buildx_buildkit_ghostnode0_state` volume with no builder is selected for removal, while the volume of the registered builder is skipped.
Two gaps in the orphan volume sweep, both pointed out in review. `any(node.startswith(builder) ...)` was not "the node belongs to a registered builder": a stock runner lists both `default-builder` and the implicit `default` builder, so `buildx_buildkit_default-builder0_state` looked reachable through `default` and would never be removed - exactly the volume this change is about. Parse the node names from the indented `\_ <node>` rows of `docker buildx ls` and compare against them. `docker buildx ls` failing left `builders` empty, which made every detached `buildx_buildkit_*_state` volume look orphaned, including the cache of a still-registered builder. Skip the sweep unless the listing succeeded and produced at least one node. Validated locally on docker 29.1.3 / buildx 0.30.1. With `default-builder` registered and inactive next to `default`, the parse yields `builders: ['default-builder', 'default']`, `nodes: ['default-builder0', 'default']`, and `buildx_buildkit_default-builder0_state` is skipped; after `docker buildx rm default-builder` the same volume is selected for removal. A failing `docker buildx ls` exits 125 with no nodes and the sweep is skipped.
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Reclaim the cache of an inactive
docker-containerbuildx builder in the docker clean up hook, so a style-checker host does not accumulate build cache untilInstall packagesfails withNo space left on device.Description
Install packages (amd_release)failed on master:CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=31f27d85ed6a30aa33cb37f57d4610362ab8bfa1&name_0=MasterCI&name_1=Install%20packages%20%28amd_release%29
The host handed the job 4.3 GiB of 58 GiB and the very first test needs about 5 GiB. This has hit master four times in the last 30 days (2026-07-31, 2026-08-03, 2026-08-04, 2026-08-30), always
amd_release, and no open issue tracks it.Root cause. Nothing the job does explains the other 54 GiB. The clean up hook that runs right before it reported
Total reclaimed space: 0Bfor bothdocker container pruneanddocker system prune, and only two images were present. The accumulator is adocker-containerbuildx builder's cache, which lives in a namedbuildx_buildkit_<node>_statevolume, and none of the commands in the hook reclaim it:docker system pruneskips volumes without--volumes;docker builder prunetalks to the daemon, so it only reclaims the cache of thedockerdriver builder - which is why it reports0Bon a host that has just built multi-platform images;inactiveand the prune fails withNo such container: buildx_buildkit_default-builder0- present verbatim in the failing job's log - leaving the cache on disk.The host had run
Docker server imageand threeDocker keeper imagejobs beforehand, each writing gigabytes into that volume;Docker server imagealone took it from 24 GiB to 35 GiB used.Change (one file). Bootstrap each builder before pruning it. An
inactivedocker-containerbuilder gets its buildkit container back, the existing per-builder prune then reaches the cache and empties the volume in place, and the builder entry -default-builderincluded - stays registered for the docker image jobs that run later on the same host. Additionally remove abuildx_buildkit_<node>_statevolume whose node is not one of the nodesdocker buildx lslists: that one is unreachable by any prune. The comparison is on the exact node name, orbuildx_buildkit_default-builder0_statewould look reachable through the unrelated implicitdefaultbuilder, and the sweep is skipped altogether unless the listing succeeded and yielded at least one node, so a failure to enumerate never reads as "nothing is registered".docker volume rmrefuses a volume attached to a running container, so a live cache cannot be thrown away here either. Also printdocker system df, because the job that runs out of disk space is rarely the job that filled it, andLocal Volumesis the row the prunes cannot reclaim.Validation. Locally against docker 29.1.3 / buildx 0.30.1:
docker-containerbuilder, container then removedinactive, 534 MiB left inbuildx_buildkit_orphantest0_statedocker buildx prune -a -f --builder <name>on itERROR: Error response from daemon: No such container: buildx_buildkit_orphantest0- the CI error textdocker builder prune -a -f,docker system prune -fon it0B/ volume untoucheddocker buildx inspect <name> --bootstrapthen the same per-builder pruneTotal: 558.7MB, the volume drops to 352 KiB,docker buildx lsstill lists the builder asrunningbuildx_buildkit_ghostnode0_statewith no builderclickhouse_integration_tests_volumeare skippeddefault-builderregistered andinactivenext todefaultnodes: ['default-builder0', 'default'],buildx_buildkit_default-builder0_stateskipped; afterdocker buildx rm default-builderthe same volume is selected for removaldocker buildx lsfailingWhat this does not do. It does not raise
runner-init's free-space guard (2.86 GiB / 5%), which is below what this job needs, so a host that arrives full for some other reason can still fail it. Related: #113605Related: #113270
Related: #113032
Related: #112687
Related: #111960
Workflow [PR]
Sync PR [sync-upstream/pr/117168]
Version info
26.9.1.567(included in26.9and later)