Skip to content

http: fix resolver cache nil race - #6791

Merged
tonistiigi merged 5 commits into
moby:masterfrom
tonistiigi:fix-http-sigsegv
Jun 2, 2026
Merged

tonistiigi merged 5 commits into
moby:masterfrom
tonistiigi:fix-http-sigsegv

Conversation

@tonistiigi

Copy link
Copy Markdown
Member

Fixes #6788
Carry #6790

bglimepoint and others added 3 commits May 20, 2026 15:54
Signed-off-by: Bryce Gibson <bgibson@limepoint.com>
Signed-off-by: Bryce Gibson <bgibson@limepoint.com>
Avoid storing typed nil HTTP metadata in the resolver cache after failed
metadata resolution. Also make resolver cache release functions consistently
callable when no error is returned.

Add a client integration test covering concurrent same-URL HTTP sources with
and without checksum when the server returns 401.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
@bglimepoint

Copy link
Copy Markdown
Contributor

Thanks! 🙏

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a crash in BuildKit’s HTTP source resolver-cache interaction by preventing nil/invalid cache values and ensuring cache lock release behavior is safe, plus adding an integration test to reproduce the original SIGSEGV scenario.

Changes:

  • Avoid storing/propagating nil resolver-cache entries from the HTTP source handler and improve invalid-cache-value diagnostics.
  • Make resolverCache.Lock() return a safe no-op release function when the key disappears, and harden combined cache locking against nil releasers.
  • Add an integration test that reproduces the 401 + checksum/no-checksum concurrency scenario.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
source/http/source.go Avoids caching nil resolved values and validates resolver-cache entries more defensively in HTTP snapshot/metadata paths.
solver/resolvercache.go Prevents nil release function returns (key-deleted case) and avoids appending nil releasers in combined cache aggregation.
client/client_test.go Adds an integration test to exercise the prior crash scenario (401 responses with concurrent HTTP sources sharing resolver-cache key).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread source/http/source.go Outdated
Comment on lines 868 to 871
v2, ok := v.(*metadataWithRef)
if !ok {
return nil, errors.Errorf("invalid HTTP resolver cache value: %T", vals[0])
if !ok || v2 == nil {
return nil, errors.Errorf("invalid HTTP resolver cache value: %T", v)
}

@crazy-max crazy-max May 28, 2026 •

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.

This copilot review looks legit.

Comment thread solver/resolvercache.go Resolved
@tonistiigi tonistiigi added this to the v0.31.0 milestone May 27, 2026
@tonistiigi tonistiigi mentioned this pull request May 27, 2026
4 tasks done
Comment thread client/client_test.go

var requests atomic.Int32
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if requests.Add(1) == 1 {

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.

Can we reset the counter per iteration so each solve forces one request to wait while the other arrives?

Move the HTTP snapshot resolver-cache lookup into a helper so the lock
release is deferred after acquisition. This keeps invalid cache entries
and digest mismatch errors from returning while the cache lock is held.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Use the resolver-cache ref ID directly when loading a cached HTTP snapshot.
This avoids dereferencing missing metadata for cache entries found during a
concurrent solve.

Reset the unauthorized checksum race request counter per solve iteration so
each retry applies the intended first-request delay.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
@tonistiigi
tonistiigi merged commit fbb261b into moby:master Jun 2, 2026
214 of 215 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SIGSEGV when running builds

4 participants