Skip to content

Rebuild against Canonical when the in-region apt mirror is broken - #115726

Merged
alexey-milovidov merged 3 commits into
masterfrom
ci-docker-apt-mirror-fallback
Aug 22, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
ci-docker-apt-mirror-fallback

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 21, 2026 •

Copy link
Copy Markdown
Member

Related: #104152
Related: #108969

The Docker server image check went red on master because us-east-1.ec2.ports.ubuntu.com answered 503 Service Unavailable for tzdata and served the other packages at ~20 kB/s. The arm64 server image burned all five BUILDX_RETRIES against that one mirror over 15 minutes and still failed; the mirror recovered about ten minutes later, and the same degraded window took out five unrelated pull requests the same night.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=096ba6c83084966d9be3b14d660db1b5186c8b12&name_0=MasterCI&name_1=Docker%20server%20image&name_1=Docker%20server%20image

--apt-mirror-region, added in 47dee58, exists because the opposite happens too: Canonical's archive.ubuntu.com and ports.ubuntu.com are frequently unreachable over IPv4 from the runners. Neither mirror can be trusted on its own, so retrying one of them harder cannot fix either failure mode.

This keeps the in-region mirror as the first choice, and when an image exhausts its retries on an apt download failure it is rebuilt once against Canonical instead of reding the check. The mirror is already a --build-arg, so the change is confined to the CI job: the published docker/server and docker/keeper Dockerfiles are untouched and still default to Canonical, as intended by 7cb4072.

The second attempt is reached only through APT_MIRROR_ERRORS, which are the signatures of a mirror not handing over a file. A broken package name, an unsatisfiable dependency or any other genuine packaging error produces none of them and still fails on the first attempt, so the retry allowlist narrowed in #108969 keeps its fail-fast property. Alpine images are unaffected: apk failures do not print any of these strings.

Measured over 180 days of CI, restricted to apt download failures in the Docker server image and Docker keeper image checks: 82 failed image builds across 12 bursty days. The nine since the in-region mirror was adopted are all arm64, that is, all on ports.ubuntu.com.

Validated by building the exact failing layer on an aarch64 host with the in-region mirror pointed at a region that does not resolve: the build fails twice against the dead mirror, is rebuilt against ports.ubuntu.com and succeeds. Also checked that a genuine build error still fails on the first attempt with no second mirror tried, that a healthy build issues exactly one buildx invocation per architecture as before, and that without --apt-mirror-region nothing changes. The package that 503'd, tzdata_2026c-0ubuntu0.22.04.1_all.deb, downloads fine from Canonical.

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

Version info

  • Merged into: 26.8.1.1913 (included in 26.8 and later)

The `Docker server image` check went red on master because
`us-east-1.ec2.ports.ubuntu.com` answered `503 Service Unavailable` for
`tzdata` and served the other packages at ~20 kB/s. The arm64 server image
burned all five `BUILDX_RETRIES` against that one mirror over 15 minutes and
still failed; the mirror only recovered about ten minutes later, and the same
degraded window took out five unrelated pull requests the same night.

`--apt-mirror-region`, added in 47dee58, exists because the opposite
happens too: Canonical's `archive.ubuntu.com` and `ports.ubuntu.com` are
frequently unreachable over IPv4 from the runners. So neither mirror can be
trusted on its own, and retrying one of them harder cannot fix either failure
mode.

Keep the in-region mirror as the first choice, and when an image exhausts its
retries on an apt *download* failure, rebuild it once against Canonical instead
of reding the check. The mirror is already a `--build-arg`, so this is confined
to the CI job: the published `docker/server` and `docker/keeper` Dockerfiles are
untouched and still default to Canonical, as intended by 7cb4072.

The second attempt is reached only through `APT_MIRROR_ERRORS`, which are the
signatures of a mirror not handing over a file. A broken package name, an
unsatisfiable dependency or any other genuine packaging error produces none of
them and still fails on the first attempt, so the narrowed retry allowlist from
pull request 108969 keeps its fail-fast property. Alpine images are unaffected:
`apk` failures do not print any of these strings.

Measured over 180 days of CI, restricted to apt download failures in the
`Docker server image` and `Docker keeper image` checks: 82 failed image builds
across 12 bursty days. The nine since the in-region mirror was adopted are all
arm64, that is, all on `ports.ubuntu.com`.

Validated by building the exact failing layer on an aarch64 host with the
in-region mirror pointed at a region that does not resolve: the build fails
twice against the dead mirror, is rebuilt against `ports.ubuntu.com` and
succeeds. Also checked that a genuine build error still fails on the first
attempt with no second mirror tried, that a healthy build issues exactly one
buildx invocation per architecture as before, and that without
`--apt-mirror-region` nothing changes. The package that 503'd,
`tzdata_2026c-0ubuntu0.22.04.1_all.deb`, downloads fine from Canonical.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=096ba6c83084966d9be3b14d660db1b5186c8b12&name_0=MasterCI&name_1=Docker%20server%20image&name_1=Docker%20server%20image

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3f7dd83]

Summary: ✅


AI Review

Summary

This PR adds a second docker buildx attempt against Canonical when a build using --apt-mirror-region appears to have failed because the in-region Ubuntu mirror was unhealthy. The overall direction makes sense, and the earlier whole-log matching problem is fixed, but the current classifier is still too broad in two places: it retries on generic apt fetch failures from repositories other than the Ubuntu mirror, and it retries on any build timeout even when the failing image/step does not use apt at all.

Missing context / blind spots
  • ⚠️ I could not run the added pytest coverage directly because this environment does not have the pytest module for /usr/bin/python3 (/usr/bin/python3: No module named pytest). Installing pytest and running ci/tests/test_docker_apt_mirror_fallback.py plus ci/tests/test_docker_buildx_timeout.py would close that gap.
Findings

⚠️ Majors

  • [ci/jobs/docker_server.py:323] is_apt_mirror_failure classifies any apt fetch failure as "the Ubuntu mirror withheld a file". In docker/server/Dockerfile.ubuntu and docker/server/Dockerfile.distroless, later apt-get steps talk to packages.clickhouse.com; a 503 there produces the same E: Failed to fetch ... / E: Unable to fetch some archives pair, so the job does a full rebuild against Canonical even though the second attempt does not change that repository at all.

  • [ci/jobs/docker_server.py:402] should_try_next_mirror treats every docker buildx timeout as mirror-related. Because build_and_push_image threads apt_mirror_region through every os, an alpine timeout or a timeout in a non-apt wget step also triggers a second full build where the only change is the unused apt_* build args, so the retry cannot address the underlying failure.

Final Verdict

Changes requested.

Comment thread ci/jobs/docker_server.py Resolved
alexey-milovidov and others added 2 commits August 22, 2026 17:50
…r-fallback

# Conflicts:
#	ci/jobs/docker_server.py
Review feedback: `is_apt_mirror_failure` matched `APT_MIRROR_ERRORS` anywhere in
`Result.info`, which is the whole `--progress=plain` build log. An `apt-get update`
that missed an index and carried on leaves `W: Failed to fetch` and `Some index files
failed to download` in the log of a step that *succeeded*, so any later failure in
that image - a misspelled package, an unsatisfiable dependency - looked mirror-related
and was rebuilt against Canonical. That both spends a whole image build on a failure
no mirror can fix and buries the real error behind it, losing the fail-fast property
the narrowed retry allowlist exists for.

Two things now narrow the match. `terminal_build_failure` returns only the fenced
context block that buildx prints for the step it stopped on, taken from the last
`ERROR: failed to solve:` so a retried build is judged by its final attempt; a log
without that shape yields nothing and the fallback is not reached, because
`Result.info` is capped at 300 lines and may be re-centred on the first `: error:`
line. Inside the block, apt's own severity decides: `W:` is a miss apt recovered from,
`E:` is the file it could not get, which also separates the two when
`apt-get update && apt-get install` share one step.

Merging master brought in the per-invocation `timeout` from pull request 115572, which
changes what the mirror failure looks like: `Acquire::http::Timeout` is an inactivity
timeout, so the mirror that trickles bytes - the 2026-08-21 failure this whole change
is about - never produces an apt error at all and is killed by the bound instead. An
expiry therefore also has to reach the next mirror, via `should_try_next_mirror`, while
a bare 137 (OOM, external kill) still must not. The extra attempt is reached only once
the build is failing anyway, and `buildx_timeout` shrinks each bound by the elapsed
time, so the job stays inside its own cap.

`ci/tests/test_docker_apt_mirror_fallback.py` pins all of it: the false positive above,
the mixed-severity step, the fail-closed unrecognized log, the last-attempt rule, the
timeout arm, the mirror order, and that the loop is wired to the classifier - driving
the real `build_and_push_image` and asserting the second invocation is a rebuild
against the other mirror, that a packaging error still issues one command, and that
without `--apt-mirror-region` nothing changes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Comment thread ci/jobs/docker_server.py
def is_apt_mirror_failure(info: str) -> bool:
"""Did the step that stopped the build fail because a mirror withheld a file?"""
return any(
APT_ERROR_SEVERITY in line and any(error in line for error in APT_MIRROR_ERRORS)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_apt_mirror_failure still treats any apt fetch failure as if it came from the Ubuntu mirror we are switching. Both docker/server/Dockerfile.ubuntu and docker/server/Dockerfile.distroless later run apt-get against packages.clickhouse.com, and a 503 there produces the same E: Failed to fetch ... / E: Unable to fetch some archives pair, so this returns True even though the retry only changes apt_archive / apt_ports_archive. That burns a full rebuild on a failure Canonical cannot fix. Could we key the fallback on the failed URL host (or at least on the specific base-image apt step) instead of any apt fetch error?

Comment thread ci/jobs/docker_server.py
has to reach the next mirror too - it is only reached once the build is failing
anyway, and `buildx_timeout` keeps the extra attempt inside the job's own cap.
"""
return is_apt_mirror_failure(info) or is_buildx_timeout(info)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The timeout arm widens the fallback to every docker buildx expiry, not just timeouts in an apt step. build_and_push_image passes apt_mirror_region through every os, so an alpine timeout or a timeout in the direct-wget path also reaches the second mirror even though the second command changes no input relevant to the failing step. I reproduced this with os='alpine': the code emits a second docker buildx for Dockerfile.alpine, and the only delta is dropping the unused apt_* build args. Could we gate the timeout fallback to apt-based images / steps instead of all build expiries?

@clickhouse-gh

clickhouse-gh Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 3f7dd8331 with master 06af43bc2 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 705.38 MiB 702.36 MiB -3.02 MiB (-0.43%)

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 units

6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline.

Job report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants