Skip to content

Commit

Permalink
fix(api/v1): avoid concurrent map writes
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanilves committed May 6, 2018
1 parent 826db81 commit e1b5f4d
Showing 1 changed file with 23 additions and 3 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

0 comments on commit e1b5f4d

Please sign in to comment.