Skip to content

Commit

Permalink
Merge pull request #3567 from justadogistaken/fix/image-cache-incomplete
Browse files Browse the repository at this point in the history
fix image cache incompletely
  • Loading branch information
joaodrp committed Jan 19, 2022
2 parents 91f33cb + 706f217 commit 5f1974a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions registry/proxy/proxyblobstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,19 @@ func (pbs *proxyBlobStore) ServeBlob(ctx context.Context, w http.ResponseWriter,
inflight[dgst] = struct{}{}
mu.Unlock()

// storeLocalCtx will be independent with ctx, because ctx it used to fetch remote image.
// There would be a situation, that is pulling remote bytes ends before pbs.storeLocal( 'Copy', 'Commit' ...)
// Then the registry fails to cache the layer, even though the layer had been served to client.
storeLocalCtx, cancel := context.WithCancel(context.Background())
go func(dgst digest.Digest) {
if err := pbs.storeLocal(ctx, dgst); err != nil {
dcontext.GetLogger(ctx).Errorf("Error committing to storage: %s", err.Error())
defer cancel()
if err := pbs.storeLocal(storeLocalCtx, dgst); err != nil {
dcontext.GetLogger(storeLocalCtx).Errorf("Error committing to storage: %s", err.Error())
}

blobRef, err := reference.WithDigest(pbs.repositoryName, dgst)
if err != nil {
dcontext.GetLogger(ctx).Errorf("Error creating reference: %s", err)
dcontext.GetLogger(storeLocalCtx).Errorf("Error creating reference: %s", err)
return
}

Expand All @@ -146,6 +151,7 @@ func (pbs *proxyBlobStore) ServeBlob(ctx context.Context, w http.ResponseWriter,

_, err = pbs.copyContent(ctx, dgst, w)
if err != nil {
cancel()
return err
}
return nil
Expand Down

0 comments on commit 5f1974a

Please sign in to comment.