@@ -24,6 +24,7 @@ import (
24
24
"github.com/moby/buildkit/solver/pb"
25
25
"github.com/moby/buildkit/source"
26
26
srctypes "github.com/moby/buildkit/source/types"
27
+ "github.com/moby/buildkit/util/bklog"
27
28
"github.com/moby/buildkit/util/tracing"
28
29
digest "github.com/opencontainers/go-digest"
29
30
"github.com/pkg/errors"
@@ -192,7 +193,12 @@ func (hs *httpSourceHandler) CacheKey(ctx context.Context, g session.Group, inde
192
193
// if metaDigest := getMetaDigest(si); metaDigest == hs.formatCacheKey("") {
193
194
if etag := md .getETag (); etag != "" {
194
195
if dgst := md .getHTTPChecksum (); dgst != "" {
195
- m [etag ] = md
196
+ // check that ref still exists
197
+ ref , err := hs .cache .Get (ctx , md .ID (), nil )
198
+ if err == nil {
199
+ m [etag ] = md
200
+ defer ref .Release (context .WithoutCancel (ctx ))
201
+ }
196
202
}
197
203
}
198
204
// }
@@ -235,6 +241,7 @@ func (hs *httpSourceHandler) CacheKey(ctx context.Context, g session.Group, inde
235
241
hs .refID = md .ID ()
236
242
dgst := md .getHTTPChecksum ()
237
243
if dgst != "" {
244
+ hs .cacheKey = dgst
238
245
modTime := md .getHTTPModTime ()
239
246
resp .Body .Close ()
240
247
return hs .formatCacheKey (getFileName (hs .src .URL , hs .src .Filename , resp ), dgst , modTime ).String (), dgst .String (), nil , true , nil
@@ -275,8 +282,10 @@ func (hs *httpSourceHandler) CacheKey(ctx context.Context, g session.Group, inde
275
282
if dgst == "" {
276
283
return "" , "" , nil , false , errors .Errorf ("invalid metadata change" )
277
284
}
285
+ hs .cacheKey = dgst
278
286
modTime := md .getHTTPModTime ()
279
287
resp .Body .Close ()
288
+
280
289
return hs .formatCacheKey (getFileName (hs .src .URL , hs .src .Filename , resp ), dgst , modTime ).String (), dgst .String (), nil , true , nil
281
290
}
282
291
@@ -421,7 +430,9 @@ func (hs *httpSourceHandler) save(ctx context.Context, resp *http.Response, s se
421
430
func (hs * httpSourceHandler ) Snapshot (ctx context.Context , g session.Group ) (cache.ImmutableRef , error ) {
422
431
if hs .refID != "" {
423
432
ref , err := hs .cache .Get (ctx , hs .refID , nil )
424
- if err == nil {
433
+ if err != nil {
434
+ bklog .G (ctx ).WithError (err ).Warnf ("failed to get HTTP snapshot for ref %s (%s)" , hs .refID , hs .src .URL )
435
+ } else {
425
436
return ref , nil
426
437
}
427
438
}
0 commit comments