Repository navigation
fix(start): use image digest for rebuild detection, fix rand and ssh-agent data races, for #8145 - #8359
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
|
Download the artifacts for this pull request:
See Testing a PR. |
…agent data races Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
941cc5a to
67ce072
Compare
There was a problem hiding this comment.
Pull request overview
Fixes ddev start correctness regressions introduced with the recent startup optimizations by making rebuild detection robust to retagging and eliminating two startup-time data races.
Changes:
- Switch build-skip fingerprinting to hash base image IDs (via
dockerutil.ImageID) instead of tag strings, and wait for background pulls before fingerprinting. - Remove shared
*rand.Randusage innodeps.RandomString()to eliminate a race by relying on the package-levelmath/randfunctions. - Reorder SSH-agent container setup to run after the chown goroutine completes to avoid a race on
app.ComposeYaml.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/nodeps/utils.go | Removes shared RNG state from RandomString() to eliminate concurrent access races. |
| pkg/dockerutil/images.go | Adds ImageID() helper to resolve a local image’s content-addressable ID for fingerprinting. |
| pkg/ddevapp/ddevapp.go | Uses image IDs for build-context fingerprinting; adjusts startup ordering to avoid SSH-agent/ComposeYaml race. |
| // buildContextFingerprint returns an SHA-256 hash of the build context directories | ||
| // (.webimageBuild, .dbimageBuild) and base image IDs. This is used to detect | ||
| // when docker-compose build can be skipped because nothing has changed. | ||
| // Image IDs (sha256 digests) are used instead of tag names so that | ||
| // rebuilt images with the same tag are still detected as changed. | ||
| func (app *DdevApp) buildContextFingerprint() string { | ||
| dirs := []string{ | ||
| app.GetConfigPath(".webimageBuild"), | ||
| app.GetConfigPath(".dbimageBuild"), | ||
| } | ||
| hash, err := fileutil.HashDirs(dirs, app.WebImage, app.GetDBImage()) | ||
| hash, err := fileutil.HashDirs(dirs, dockerutil.ImageID(app.WebImage), dockerutil.ImageID(app.GetDBImage())) | ||
| if err != nil { |
There was a problem hiding this comment.
This changes the build-skip fingerprinting behavior (using ImageID/tag digest resolution and waiting for pulls before hashing), but there’s no test exercising the regression case where a base image tag is moved to a different image. Please add/extend a start-related integration test to assert that changing the underlying image for app.WebImage/app.GetDBImage() triggers a rebuild, and that subsequent starts do not rebuild when the digest is unchanged.
There was a problem hiding this comment.
This would require a full integration test with a live Docker daemon, image tagging, and a ddev start cycle - closer to a manual scenario than a unit test. The manual testing steps in the PR description cover this case. Skipping for now as this is a focused bugfix PR.
rfay
left a comment
There was a problem hiding this comment.
Masterful work, and such a small PR for such important fixes. thank you!
| // (.webimageBuild, .dbimageBuild) and base image IDs. This is used to detect | ||
| // when docker-compose build can be skipped because nothing has changed. | ||
| // Image IDs (sha256 digests) are used instead of tag names so that | ||
| // rebuilt images with the same tag are still detected as changed. |
There was a problem hiding this comment.
What is an example of when this happens? (same tag, new SHA)?
There was a problem hiding this comment.
It happened in:
I pushed the image several times there and was confused why I didn't see the changes after ddev utility download-images && ddev restart.
We don't need to re-push the image to test this behavior - the OP already has a reproduction using docker tag, which is basically the same thing.
|
I think we need more sophisticated rebuild detection. For example, these Docker-related values can change:
All of them should be part of the build hash. |
The Issue
When a Docker image tag is moved to a different image (e.g. after a second push or a
docker tag),ddev startdoesn't rebuild the project images because the old fingerprint still matches the tag name.Race condition in https://github.com/ddev/ddev/actions/runs/25064604457/job/73428302255#step:13:563
Two concurrent goroutines (
PopulateGlobalCustomCommandFilesandStartDdevRouter →PushGlobalTraefikConfig→ ListFilesInVolume) both callRandomString(), which uses a shared*rand.Randinstance (seededRand) without locking:Race condition in https://github.com/ddev/ddev/actions/runs/25065414461/job/73431107278#step:13:16538
The chown goroutine called
EnsureSSHAgentContainer()after finishing chown, butEnsureSSHAgentContainer()readsapp.ComposeYamlwhile the main goroutine was concurrently writing it insideWriteDockerComposeYAML():How This PR Solves The Issue
For 1:
buildContextFingerprint()now callsdockerutil.ImageID()to resolve each tag to itssha256:content-addressable digest before hashing. If a tag is re-pointed to a different image, the digest changes and the build is triggered.pullWg.Wait()is placed before the fingerprint check so the digest reflects the freshly-pulled image rather than a stale local one.For 2: Remove the shared
*rand.Randinstance (seededRand) and replace all calls with the package-levelrand.Intn(), which has been auto-seeded and internally locked since Go 1.20. This project requires Go 1.25, so it is guaranteed safe, see https://pkg.go.dev/math/rand#SeedFor 3: Move
EnsureSSHAgentContainer()out of the chown goroutine and run it sequentially afterchownWg.Wait(), which happens afterWriteDockerComposeYAML()completes. This preserves the chown parallelism while eliminating the read/write race onapp.ComposeYaml.Manual Testing Instructions
Using this PR, the webserver image is rebuilt on tag change: