cmd/dist/fetch: address subtle concurrency bug

When using the fetcher concurrently, the loop modifying the closed
`base` parameter was causing urls from different digests to be returned
randomly. We copy the the value and then modify it to make it work
correctly.

Luckily, we are using content addressable storage or this would have
been undetectable.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day
2017-02-24 18:31:26 -08:00
parent 0f76e0a5b3
commit 2e0c92b168

6
cmd/dist/fetch.go vendored
View File

@@ -139,11 +139,11 @@ func getResolver(ctx contextpkg.Context) (remotes.Resolver, error) {
} }
for _, path := range paths { for _, path := range paths {
base.Path = path url := base
url := base.String() url.Path = path
log.G(ctx).WithField("url", url).Debug("fetch content") log.G(ctx).WithField("url", url).Debug("fetch content")
req, err := http.NewRequest(http.MethodGet, url, nil) req, err := http.NewRequest(http.MethodGet, url.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }