Merge pull request #3567 from justadogistaken/fix/image-cache-incomplete

fix image cache incompletely
This commit is contained in:
João Pereira 2022-01-19 13:57:27 +00:00 committed by GitHub
commit 5f1974ab8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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
}
@ -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