Explorar o código

c8d/push: Sync mountableBlobs access

Handler is called in parallel and modifying a map without
synchronization is a race condition.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Paweł Gronowski %!s(int64=2) %!d(string=hai) anos
pai
achega
c9012c798e
Modificáronse 1 ficheiros con 5 adicións e 1 borrados
  1. 5 1
      daemon/containerd/image_push.go

+ 5 - 1
daemon/containerd/image_push.go

@@ -5,6 +5,7 @@ import (
 	"fmt"
 	"fmt"
 	"io"
 	"io"
 	"strings"
 	"strings"
+	"sync"
 
 
 	"github.com/containerd/containerd/content"
 	"github.com/containerd/containerd/content"
 	cerrdefs "github.com/containerd/containerd/errdefs"
 	cerrdefs "github.com/containerd/containerd/errdefs"
@@ -136,8 +137,9 @@ func (i *ImageService) findMissingMountable(ctx context.Context, store content.S
 	target ocispec.Descriptor, targetRef reference.Named, limiter *semaphore.Weighted,
 	target ocispec.Descriptor, targetRef reference.Named, limiter *semaphore.Weighted,
 ) (map[digest.Digest]distributionSource, error) {
 ) (map[digest.Digest]distributionSource, error) {
 	mountableBlobs := map[digest.Digest]distributionSource{}
 	mountableBlobs := map[digest.Digest]distributionSource{}
-	sources, err := getDigestSources(ctx, store, target.Digest)
+	var mutex sync.Mutex
 
 
+	sources, err := getDigestSources(ctx, store, target.Digest)
 	if err != nil {
 	if err != nil {
 		if !errdefs.IsNotFound(err) {
 		if !errdefs.IsNotFound(err) {
 			return nil, err
 			return nil, err
@@ -155,7 +157,9 @@ func (i *ImageService) findMissingMountable(ctx context.Context, store content.S
 
 
 			for _, source := range sources {
 			for _, source := range sources {
 				if canBeMounted(desc.MediaType, targetRef, i.registryService.IsInsecureRegistry, source) {
 				if canBeMounted(desc.MediaType, targetRef, i.registryService.IsInsecureRegistry, source) {
+					mutex.Lock()
 					mountableBlobs[desc.Digest] = source
 					mountableBlobs[desc.Digest] = source
+					mutex.Unlock()
 					jobs.Add(desc)
 					jobs.Add(desc)
 					break
 					break
 				}
 				}