@@ -272,7 +272,7 @@ func (r *Resolver) Resolve(ctx context.Context, hosts source.RegistryHosts, refs
272272 log .G (ctx ).Debugf ("resolving" )
273273
274274 // Resolve the blob.
275- blobR , err := r .resolveBlob (ctx , hosts , refspec , desc )
275+ blobR , err := r .resolveBlob (ctx , hosts , refspec , desc , name )
276276 if err != nil {
277277 return nil , errors .Wrapf (err , "failed to resolve the blob" )
278278 }
@@ -315,6 +315,11 @@ func (r *Resolver) Resolve(ctx context.Context, hosts source.RegistryHosts, refs
315315 }), 0 , blobR .Size ())
316316 vr , err := r .newReader (sr , desc , fsCache , esgzOpts ... )
317317 if err != nil {
318+ if errors .Is (err , context .DeadlineExceeded ) {
319+ r .blobCacheMu .Lock ()
320+ r .blobCache .Remove (name )
321+ r .blobCacheMu .Unlock ()
322+ }
318323 return nil , errors .Wrap (err , "failed to read layer" )
319324 }
320325 // do not propagate context after resolve is done
@@ -361,12 +366,10 @@ func (r *Resolver) newReader(sr *io.SectionReader, desc ocispec.Descriptor, fsCa
361366}
362367
363368// 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 ) {
367370 // Try to retrieve the blob from the underlying cache.
368371 r .blobCacheMu .Lock ()
369- c , done , ok := r .blobCache .Get (name )
372+ c , done , ok := r .blobCache .Get (cacheKey )
370373 r .blobCacheMu .Unlock ()
371374 if ok {
372375 blob := c .(remote.Blob )
@@ -376,7 +379,7 @@ func (r *Resolver) resolveBlob(ctx context.Context, hosts source.RegistryHosts,
376379 // invalid blob. discard this.
377380 done ()
378381 r .blobCacheMu .Lock ()
379- r .blobCache .Remove (name )
382+ r .blobCache .Remove (cacheKey )
380383 r .blobCacheMu .Unlock ()
381384 }
382385
@@ -396,7 +399,7 @@ func (r *Resolver) resolveBlob(ctx context.Context, hosts source.RegistryHosts,
396399 return nil , errors .Wrap (err , "failed to resolve the source" )
397400 }
398401 r .blobCacheMu .Lock ()
399- cachedB , done , added := r .blobCache .Add (name , b )
402+ cachedB , done , added := r .blobCache .Add (cacheKey , b )
400403 r .blobCacheMu .Unlock ()
401404 if ! added {
402405 b .Close () // blob already exists in the cache. discard this.
0 commit comments