Skip to content

fix(compose): remove BuildKit snapshot race retry logic, for #8136 - #8637

Merged
rfay merged 1 commit into
ddev:mainfrom
rfay:20260730_rfay_docker29
Jul 31, 2026
Merged

rfay merged 1 commit into
ddev:mainfrom
rfay:20260730_rfay_docker29

Conversation

@rfay

@rfay rfay commented Jul 30, 2026 •

Copy link
Copy Markdown
Member

The Issue

Docker 29 made the containerd image store the default storage driver,
which exposed a race condition in containerd/BuildKit: when
docker-compose build builds multiple services in parallel that share
base layers, containerd's GC could delete a parent snapshot while a
concurrent image export still depended on it, failing with:

failed to prepare extraction snapshot "extract-...": parent snapshot ... does not exist: not found

This showed up intermittently in DDEV's own CI (parallel web/db
image builds) once GitHub Actions runners moved to Docker 29.

History of the issue and its fixes

How This PR Solves The Issue

Removes the retry/detection logic added in #8142, leaving
composeBuild() as a single, plain build attempt:

  • Removed the composeBuildMaxRetries constant.
  • Removed the retry loop, the "parent snapshot" / "does not exist"
    error-text matching, and the associated warning/debug logging.
  • Kept the composeBuild() helper itself (a useful consolidation of
    the build call used by both the initial project build and the
    dirty-web-image --no-cache rebuild) and kept the compose-library
    based build call (LoadComposeProject / svc.Build) introduced
    later in feat: use docker-compose library, optionally download docker-buildx, fixes #7915, for #8295 #8234, which is unrelated to the race workaround.

No other files in the repository referenced the retry logic, the
composeBuildMaxRetries constant, or the snapshot-race error text, so
this is a self-contained change to pkg/ddevapp/ddevapp.go.

Manual Testing Instructions

I think if this passes normal testing it should be OK.

Automated Testing Overview

Should still do the same things it did before.

## The Issue

- For ddev#8136

Docker 29 made the containerd image store the default storage driver,
which exposed a race condition in containerd/BuildKit: when
`docker-compose build` builds multiple services in parallel that share
base layers, containerd's GC could delete a parent snapshot while a
concurrent image export still depended on it, failing with:

```
failed to prepare extraction snapshot "extract-...": parent snapshot ... does not exist: not found
```

This showed up intermittently in DDEV's own CI (parallel `web`/`db`
image builds) once GitHub Actions runners moved to Docker 29.

### History of the issue and its fixes

- ddev#8136 opened tracking the CI failures against Docker 29 / containerd
  snapshotter, with links to the relevant upstream issues:
  - containerd/containerd#3787, containerd/containerd#2382,
    containerd/containerd#10835 (the snapshot-GC race itself)
  - containerd/containerd#10723 (upstream fix, cherry-picked to
    release/1.7 in #10763 and release/1.6 in #10764)
  - moby/buildkit#4024, moby/buildkit#6521 (BuildKit-level reports)
  - moby/moby#51665, containerd/nerdctl#3420 (downstream reports)
- ddev#8142 (this repo) added a transient workaround: `composeBuild()` was
  extracted from the inline build logic in `Start()` and given a retry
  loop (`composeBuildMaxRetries = 3`) that detected the race by
  matching `"parent snapshot"` + `"does not exist"` in the build error
  output and retried the whole `docker-compose build` on match.
- moby/buildkit#6558 landed the upstream fix for the race in BuildKit
  itself, and it shipped in a subsequent `moby/moby` bump of its
  `github.com/moby/buildkit` dependency.
- Per the follow-up comment on ddev#8136, with the fix available upstream
  the retry logic "should be removed - everything is fixed upstream."

## How This PR Solves The Issue

Removes the retry/detection logic added in ddev#8142, leaving
`composeBuild()` as a single, plain build attempt:

- Removed the `composeBuildMaxRetries` constant.
- Removed the retry loop, the `"parent snapshot"` / `"does not exist"`
  error-text matching, and the associated warning/debug logging.
- Kept the `composeBuild()` helper itself (a useful consolidation of
  the build call used by both the initial project build and the
  dirty-web-image `--no-cache` rebuild) and kept the compose-library
  based build call (`LoadComposeProject` / `svc.Build`) introduced
  later in ddev#8234, which is unrelated to the race workaround.

No other files in the repository referenced the retry logic, the
`composeBuildMaxRetries` constant, or the snapshot-race error text, so
this is a self-contained change to `pkg/ddevapp/ddevapp.go`.

## Manual Testing Instructions

1. Build DDEV from this branch: `make`
2. Create and start a test project:
   ```
   mkdir ~/tmp/test-8136 && cd ~/tmp/test-8136
   ddev config --project-type=php --docroot=web
   ddev start -y
   ```
   Confirm the project builds and starts normally (parallel `web` +
   `db` image build, no retry warnings).
3. Exercise the `--no-cache` dirty-web-image rebuild path and the
   `--no-cache` flag generally:
   ```
   ddev start --no-cache
   ```
4. `ddev delete -Oy` to clean up.

## Automated Testing Overview

- `go build ./...`, `gofmt -l`, `go vet ./pkg/ddevapp/...`, and
  `make staticrequired` all pass.
- `go test -v ./cmd/ddev/cmd/... -run TestCmdStartRestartNoCache`
  passes, exercising the `--no-cache` build path used by
  `composeBuild()`.
- `go test -v ./pkg/ddevapp/... -run TestDdevStart` passes, exercising
  the normal parallel image build path.
- No existing test referenced `composeBuild`, `composeBuildMaxRetries`,
  or the snapshot-race error text, so no test changes were needed.

## Release/Deployment Notes

Pure removal of dead workaround code; no behavior change for the
normal (non-racing) build path. If the upstream BuildKit fix has not
actually propagated into the Docker/containerd versions users run,
this could reintroduce intermittent build failures on Docker 29+; the
issue history (moby/buildkit#6558 and the subsequent `moby/moby`
dependency bump) indicates the fix is available upstream.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017uQBexzcjiKGsCGUcUiUeU
@rfay
rfay requested a review from a team as a code owner July 30, 2026 21:58
@github-actions

Copy link
Copy Markdown

@rfay
rfay requested a review from stasadev July 31, 2026 12:03

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

Looks good to me.

@rfay
rfay merged commit e42f244 into ddev:main Jul 31, 2026
56 of 57 checks passed
@rfay
rfay deleted the 20260730_rfay_docker29 branch July 31, 2026 14:35
rfay added a commit to weitzman/ddev that referenced this pull request Jul 31, 2026
nikmeiser pushed a commit to awslabs/automated-security-helper that referenced this pull request Sep 19, 2026
The nerdctl leg of validate-container fails about one run in eighteen after
the image has already been built. Measured across every ASH - Unified CI run
since the leg landed: 136 passes, 3 failures of this shape, 5 further failures
that were a branch defect failing podman and finch in the same runs.

The build succeeds -- every stage completes, all 11 scanner tools verify on
PATH, the manifest and config export, the tarball sends, #48 DONE. What fails
is loading that tarball into containerd:

  level=fatal msg="apply layer error for \"...:ci\": failed to prepare
    extraction snapshot \"extract-...\": parent snapshot sha256:594f27ed...
    does not exist: not found"

Traced rather than guessed. nerdctl asks buildkit whether its worker shares
containerd's image store (pkg/cmd/builder/build.go, isImageSharable). The
nerdctl-full bundle runs the oci worker, which does not, so nerdctl takes the
else branch -- --output type=docker plus needsLoading -- and pipes the
docker-format tarball through its own loadImage, which calls containerd's
client Unpack. "apply layer error for" is that function's message and it lives
in containerd's client/image.go, not in nerdctl and not in buildkit. Unpack
walks layers with the per-layer rootfs.ApplyLayer, whose Stat-then-Prepare
window does not hold the parent snapshot under a lease, so a concurrent GC
pass can collect the parent between the two calls.

This is containerd/nerdctl#3420, reported with the same string. moby/buildkit#6558
fixed the same race but only in buildkit's own exporter, for the
type=image,unpack=true path; that fix is in the bundled buildkit 0.31.2, which
is consistent with #48 DONE succeeding. Nothing has landed for the
containerd-client side the tarball round trip routes through, so there is no
version to bump to.

Three mechanisms were separated rather than assumed:

Not a deterministic defect in the action. Pull request 608's merge queue built
this image five times from the same content -- four passed, one hit this error.
Nothing in the repository distinguishes them.

Not runner resource exhaustion. No ENOSPC or disk signal appears anywhere in
the job log, and the timing rules it out: "sending tarball 3.7s done" at
20:10:26.1608 and the fatal at 20:10:26.2090, 48 ms later. A multi-gigabyte
extraction cannot exhaust disk in 48 ms; it failed on the first Prepare,
before writing layer data.

The snapshot race in the buildkit-to-containerd handoff, which the
docker-format tarball round trip selects. Established above.

The retry only retries this error -- any other status exits immediately with
its own code, so a real build break still fails fast on the first attempt.
Retries deliberately drop --force, which is --no-cache: attempt 1 still proves
a from-scratch build, and the retry then reuses the layers just built so it
costs about a minute instead of seven and spends that minute re-running exactly
the operation that raced. That works because BUILD_DATE_EPOCH, the one
build-arg that changes per invocation, is consumed on the last line of the core
stage rather than near its top. The half-imported image is cleared first so the
retry rebuilds the snapshot chain instead of taking the same lease-skipping
Stat shortcut over it.

Configuring buildkitd with the containerd worker would skip the tarball
entirely, and was rejected: it would have this gate test a configuration no
nerdctl-full user has, so the default path would stop being measured while CI
went green.

No CI re-run of a job that hit this error exists, so "a retry succeeds" rests
on the cross-run evidence above and on ddev/ddev#8142, which carried a max-3
retry on this same error text until ddev/ddev#8637 removed it once their path
got its upstream fix. The ::warning:: on every retry is what closes that gap,
making the race countable in the Actions UI.

Verified: the extracted run block was exercised under the same shell flags
GitHub uses for a composite bash step, with a stubbed ash, across six cases --
race-then-succeed, race on every attempt, a non-race failure, a clean first
pass, a click UsageError exit 2, and an ANSI-prefixed race line. Each retried
only when intended and preserved the build's own exit code. shellcheck -S style
is clean. tests/unit/test_oci_runner_ci_coverage.py, which parses this action
against the workflow matrix, passes 5/5, and the container build path tests
pass 113/113.
nikmeiser pushed a commit to awslabs/automated-security-helper that referenced this pull request Sep 19, 2026
The nerdctl leg of validate-container fails about one run in eighteen after
the image has already been built. Measured across every ASH - Unified CI run
since the leg landed: 136 passes, 3 failures of this shape, 5 further failures
that were a branch defect failing podman and finch in the same runs.

The build succeeds -- every stage completes, all 11 scanner tools verify on
PATH, the manifest and config export, the tarball sends, #48 DONE. What fails
is loading that tarball into containerd:

  level=fatal msg="apply layer error for \"...:ci\": failed to prepare
    extraction snapshot \"extract-...\": parent snapshot sha256:594f27ed...
    does not exist: not found"

Traced rather than guessed. nerdctl asks buildkit whether its worker shares
containerd's image store (pkg/cmd/builder/build.go, isImageSharable). The
nerdctl-full bundle runs the oci worker, which does not, so nerdctl takes the
else branch -- --output type=docker plus needsLoading -- and pipes the
docker-format tarball through its own loadImage, which calls containerd's
client Unpack. "apply layer error for" is that function's message and it lives
in containerd's client/image.go, not in nerdctl and not in buildkit. Unpack
walks layers with the per-layer rootfs.ApplyLayer, whose Stat-then-Prepare
window does not hold the parent snapshot under a lease, so a concurrent GC
pass can collect the parent between the two calls.

This is containerd/nerdctl#3420, reported with the same string. moby/buildkit#6558
fixed the same race but only in buildkit's own exporter, for the
type=image,unpack=true path; that fix is in the bundled buildkit 0.31.2, which
is consistent with #48 DONE succeeding. Nothing has landed for the
containerd-client side the tarball round trip routes through, so there is no
version to bump to.

Three mechanisms were separated rather than assumed:

Not a deterministic defect in the action. Pull request 608's merge queue built
this image five times from the same content -- four passed, one hit this error.
Nothing in the repository distinguishes them.

Not runner resource exhaustion. No ENOSPC or disk signal appears anywhere in
the job log, and the timing rules it out: "sending tarball 3.7s done" at
20:10:26.1608 and the fatal at 20:10:26.2090, 48 ms later. A multi-gigabyte
extraction cannot exhaust disk in 48 ms; it failed on the first Prepare,
before writing layer data.

The snapshot race in the buildkit-to-containerd handoff, which the
docker-format tarball round trip selects. Established above.

The retry only retries this error -- any other status exits immediately with
its own code, so a real build break still fails fast on the first attempt.
Retries deliberately drop --force, which is --no-cache: attempt 1 still proves
a from-scratch build, and the retry then reuses the layers just built so it
costs about a minute instead of seven and spends that minute re-running exactly
the operation that raced. That works because BUILD_DATE_EPOCH, the one
build-arg that changes per invocation, is consumed on the last line of the core
stage rather than near its top. The half-imported image is cleared first so the
retry rebuilds the snapshot chain instead of taking the same lease-skipping
Stat shortcut over it.

Configuring buildkitd with the containerd worker would skip the tarball
entirely, and was rejected: it would have this gate test a configuration no
nerdctl-full user has, so the default path would stop being measured while CI
went green.

No CI re-run of a job that hit this error exists, so "a retry succeeds" rests
on the cross-run evidence above and on ddev/ddev#8142, which carried a max-3
retry on this same error text until ddev/ddev#8637 removed it once their path
got its upstream fix. The ::warning:: on every retry is what closes that gap,
making the race countable in the Actions UI.

Verified: the extracted run block was exercised under the same shell flags
GitHub uses for a composite bash step, with a stubbed ash, across six cases --
race-then-succeed, race on every attempt, a non-race failure, a clean first
pass, a click UsageError exit 2, and an ANSI-prefixed race line. Each retried
only when intended and preserved the build's own exit code. shellcheck -S style
is clean. tests/unit/test_oci_runner_ci_coverage.py, which parses this action
against the workflow matrix, passes 5/5, and the container build path tests
pass 113/113.
nikmeiser pushed a commit to awslabs/automated-security-helper that referenced this pull request Sep 19, 2026
The nerdctl leg of validate-container fails about one run in eighteen after
the image has already been built. Measured across every ASH - Unified CI run
since the leg landed: 136 passes, 3 failures of this shape, 5 further failures
that were a branch defect failing podman and finch in the same runs.

The build succeeds -- every stage completes, all 11 scanner tools verify on
PATH, the manifest and config export, the tarball sends, #48 DONE. What fails
is loading that tarball into containerd:

  level=fatal msg="apply layer error for \"...:ci\": failed to prepare
    extraction snapshot \"extract-...\": parent snapshot sha256:594f27ed...
    does not exist: not found"

Traced rather than guessed. nerdctl asks buildkit whether its worker shares
containerd's image store (pkg/cmd/builder/build.go, isImageSharable). The
nerdctl-full bundle runs the oci worker, which does not, so nerdctl takes the
else branch -- --output type=docker plus needsLoading -- and pipes the
docker-format tarball through its own loadImage, which calls containerd's
client Unpack. "apply layer error for" is that function's message and it lives
in containerd's client/image.go, not in nerdctl and not in buildkit. Unpack
walks layers with the per-layer rootfs.ApplyLayer, whose Stat-then-Prepare
window does not hold the parent snapshot under a lease, so a concurrent GC
pass can collect the parent between the two calls.

This is containerd/nerdctl#3420, reported with the same string. moby/buildkit#6558
fixed the same race but only in buildkit's own exporter, for the
type=image,unpack=true path; that fix is in the bundled buildkit 0.31.2, which
is consistent with #48 DONE succeeding. Nothing has landed for the
containerd-client side the tarball round trip routes through, so there is no
version to bump to.

Three mechanisms were separated rather than assumed:

Not a deterministic defect in the action. Pull request 608's merge queue built
this image five times from the same content -- four passed, one hit this error.
Nothing in the repository distinguishes them.

Not runner resource exhaustion. No ENOSPC or disk signal appears anywhere in
the job log, and the timing rules it out: "sending tarball 3.7s done" at
20:10:26.1608 and the fatal at 20:10:26.2090, 48 ms later. A multi-gigabyte
extraction cannot exhaust disk in 48 ms; it failed on the first Prepare,
before writing layer data.

The snapshot race in the buildkit-to-containerd handoff, which the
docker-format tarball round trip selects. Established above.

The retry only retries this error -- any other status exits immediately with
its own code, so a real build break still fails fast on the first attempt.
Retries deliberately drop --force, which is --no-cache: attempt 1 still proves
a from-scratch build, and the retry then reuses the layers just built so it
costs about a minute instead of seven and spends that minute re-running exactly
the operation that raced. That works because BUILD_DATE_EPOCH, the one
build-arg that changes per invocation, is consumed on the last line of the core
stage rather than near its top. The half-imported image is cleared first so the
retry rebuilds the snapshot chain instead of taking the same lease-skipping
Stat shortcut over it.

Configuring buildkitd with the containerd worker would skip the tarball
entirely, and was rejected: it would have this gate test a configuration no
nerdctl-full user has, so the default path would stop being measured while CI
went green.

No CI re-run of a job that hit this error exists, so "a retry succeeds" rests
on the cross-run evidence above and on ddev/ddev#8142, which carried a max-3
retry on this same error text until ddev/ddev#8637 removed it once their path
got its upstream fix. The ::warning:: on every retry is what closes that gap,
making the race countable in the Actions UI.

Verified: the extracted run block was exercised under the same shell flags
GitHub uses for a composite bash step, with a stubbed ash, across six cases --
race-then-succeed, race on every attempt, a non-race failure, a clean first
pass, a click UsageError exit 2, and an ANSI-prefixed race line. Each retried
only when intended and preserved the build's own exit code. shellcheck -S style
is clean. tests/unit/test_oci_runner_ci_coverage.py, which parses this action
against the workflow matrix, passes 5/5, and the container build path tests
pass 113/113.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants