Skip to content

Commit

Permalink
Merge pull request #158 from ivanilves/fix-nils-and-concurrent-map-wr…
Browse files Browse the repository at this point in the history
…ites

Fix nils and concurrent map writes
  • Loading branch information
vonrabbe authored May 6, 2018
2 parents 1f0920e + e1b5f4d commit 934ee4d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
26 changes: 23 additions & 3 deletions api/v1/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ func (api *API) CollectTags(refs ...string) (*collection.Collection, error) {
return nil, err
}

type rtags struct {
ref string
tags []*tag.Tag
}

tagc := make(chan rtags, len(refs))

tags := make(map[string][]*tag.Tag)

batchedSlicesOfRefs := getBatchedSlices(api.config.ConcurrentRequests, refs...)
Expand Down Expand Up @@ -151,10 +158,9 @@ func (api *API) CollectTags(refs ...string) (*collection.Collection, error) {
localTags,
repo.Tags(),
)
log.Debugf("%s joined tags: %+v", fn(repo.Ref()), joinedTags)

tags[repo.Ref()] = tag.Collect(sortedKeys, tagNames, joinedTags)
log.Debugf("%s sending joined tags: %+v", fn(repo.Ref()), joinedTags)

tagc <- rtags{ref: repo.Ref(), tags: tag.Collect(sortedKeys, tagNames, joinedTags)}
done <- nil

log.Infof("FETCHED %s", repo.Ref())
Expand All @@ -168,6 +174,20 @@ func (api *API) CollectTags(refs ...string) (*collection.Collection, error) {
}
}

step := 1
size := cap(tagc)
for t := range tagc {
log.Debugf("[%s] receiving tags: %+v", t.ref, t.tags)

tags[t.ref] = t.tags

if step >= size {
close(tagc)
}

step++
}

log.Debugf("%s tags: %+v", fn(), tags)

return collection.New(refs, tags)
Expand Down
6 changes: 4 additions & 2 deletions tag/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ func httpRetriableRequest(url, authorization, mode string) (*http.Response, erro
return resp, nil
}

if resp.StatusCode >= 400 && resp.StatusCode < 500 {
return nil, err
if resp != nil {
if resp.StatusCode >= 400 && resp.StatusCode < 500 {
return nil, err
}
}

if try < tries {
Expand Down

0 comments on commit 934ee4d

Please sign in to comment.