diff --git a/distribution/push_v2.go b/distribution/push_v2.go index d2012704db..41d4e69e91 100644 --- a/distribution/push_v2.go +++ b/distribution/push_v2.go @@ -29,7 +29,7 @@ import ( "github.com/docker/docker/registry" ) -const maxRepositoryMountAttempts = 3 +const maxRepositoryMountAttempts = 4 // PushResult contains the tag, manifest digest, and manifest size from the // push. It's used to signal this information to the trust code in the client @@ -379,9 +379,10 @@ func (pd *v2PushDescriptor) Upload(ctx context.Context, progressOutput progress. pd.v2MetadataService.Remove(mountCandidate) } - layerUpload = lu - if layerUpload != nil { - break + if lu != nil { + // cancel previous upload + cancelLayerUpload(ctx, mountCandidate.Digest, layerUpload) + layerUpload = lu } } @@ -583,3 +584,13 @@ func getPathComponents(path string) []string { } return strings.Split(path, "/") } + +func cancelLayerUpload(ctx context.Context, dgst digest.Digest, layerUpload distribution.BlobWriter) { + if layerUpload != nil { + logrus.Debugf("cancelling upload of blob %s", dgst) + err := layerUpload.Cancel(ctx) + if err != nil { + logrus.Warnf("failed to cancel upload: %v", err) + } + } +}