@@ -272,7 +272,7 @@ func (r *Resolver) Resolve(ctx context.Context, hosts source.RegistryHosts, refs
272
272
log .G (ctx ).Debugf ("resolving" )
273
273
274
274
// Resolve the blob.
275
- blobR , err := r .resolveBlob (ctx , hosts , refspec , desc )
275
+ blobR , err := r .resolveBlob (ctx , hosts , refspec , desc , name )
276
276
if err != nil {
277
277
return nil , errors .Wrapf (err , "failed to resolve the blob" )
278
278
}
@@ -315,6 +315,11 @@ func (r *Resolver) Resolve(ctx context.Context, hosts source.RegistryHosts, refs
315
315
}), 0 , blobR .Size ())
316
316
vr , err := r .newReader (sr , desc , fsCache , esgzOpts ... )
317
317
if err != nil {
318
+ if errors .Is (err , context .DeadlineExceeded ) {
319
+ r .blobCacheMu .Lock ()
320
+ r .blobCache .Remove (name )
321
+ r .blobCacheMu .Unlock ()
322
+ }
318
323
return nil , errors .Wrap (err , "failed to read layer" )
319
324
}
320
325
// do not propagate context after resolve is done
@@ -361,12 +366,10 @@ func (r *Resolver) newReader(sr *io.SectionReader, desc ocispec.Descriptor, fsCa
361
366
}
362
367
363
368
// resolveBlob resolves a blob based on the passed layer blob information.
364
- func (r * Resolver ) resolveBlob (ctx context.Context , hosts source.RegistryHosts , refspec reference.Spec , desc ocispec.Descriptor ) (_ * blobRef , retErr error ) {
365
- name := refspec .String () + "/" + desc .Digest .String ()
366
-
369
+ func (r * Resolver ) resolveBlob (ctx context.Context , hosts source.RegistryHosts , refspec reference.Spec , desc ocispec.Descriptor , cacheKey string ) (_ * blobRef , retErr error ) {
367
370
// Try to retrieve the blob from the underlying cache.
368
371
r .blobCacheMu .Lock ()
369
- c , done , ok := r .blobCache .Get (name )
372
+ c , done , ok := r .blobCache .Get (cacheKey )
370
373
r .blobCacheMu .Unlock ()
371
374
if ok {
372
375
blob := c .(remote.Blob )
@@ -376,7 +379,7 @@ func (r *Resolver) resolveBlob(ctx context.Context, hosts source.RegistryHosts,
376
379
// invalid blob. discard this.
377
380
done ()
378
381
r .blobCacheMu .Lock ()
379
- r .blobCache .Remove (name )
382
+ r .blobCache .Remove (cacheKey )
380
383
r .blobCacheMu .Unlock ()
381
384
}
382
385
@@ -396,7 +399,7 @@ func (r *Resolver) resolveBlob(ctx context.Context, hosts source.RegistryHosts,
396
399
return nil , errors .Wrap (err , "failed to resolve the source" )
397
400
}
398
401
r .blobCacheMu .Lock ()
399
- cachedB , done , added := r .blobCache .Add (name , b )
402
+ cachedB , done , added := r .blobCache .Add (cacheKey , b )
400
403
r .blobCacheMu .Unlock ()
401
404
if ! added {
402
405
b .Close () // blob already exists in the cache. discard this.
0 commit comments