github-vet / github-vet/rangeloop-pointer-findings

fluxcd/flux: pkg/registry/cache/repocachemanager.go; 46 LoC

Open
#9,230 0 comments 0 reactions 0 assignees View on GitHub
fresh small
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [fluxcd/flux](https://www.github.com/fluxcd/flux) at [pkg/registry/cache/repocachemanager.go](https://github.com/fluxcd/flux/blob/34c3f2f5acfdbb197a3783b3cfd1dfab66a1ecc0/pkg/registry/cache/repocachemanager.go#L192-L237)

Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first
issue it finds, so please do not limit your consideration to the contents of the below message.

> range-loop variable up used in defer or goroutine at line 223

[Click here to see the code in its original context.](https://github.com/fluxcd/flux/blob/34c3f2f5acfdbb197a3783b3cfd1dfab66a1ecc0/pkg/registry/cache/repocachemanager.go#L192-L237)

Click here to show the 46 line(s) of Go which triggered the analyzer.

```go
for _, up := range images {
// to avoid race condition, when accessing it in the go routine
upCopy := up
select {
case <-ctxc.Done():
break updates
case fetchers <- struct{}{}:
}
awaitFetchers.Add(1)
go func() {
defer func() { awaitFetchers.Done(); <-fetchers }()
ctxcc, cancel := context.WithTimeout(ctxc, c.clientTimeout)
defer cancel()
entry, err := c.updateImage(ctxcc, upCopy)
if err != nil {
if err, ok := errors.Cause(err).(net.Error); (ok && err.Timeout()) || ctxcc.Err() == context.DeadlineExceeded {
// This was due to a context timeout, don't bother logging
return
}
switch {
case strings.Contains(err.Error(), "429"):
// abort the image tags fetching if we've been rate limited
warnAboutRateLimit.Do(func() {
c.logger.Log("warn", "aborting image tag fetching due to rate limiting, will try again later")
cancel()
})
case strings.Contains(err.Error(), "manifest unknown"):
// Registry is corrupted, keep going, this manifest may not be relevant for automatic updates
c.Lock()
manifestUnknownCount++
c.Unlock()
c.logger.Log("warn", fmt.Sprintf("manifest for tag %s missing in repository %s", up.ref.Tag, up.ref.Name),
"impact", "flux will fail to auto-release workloads with matching images, ask the repository administrator to fix the inconsistency")
default:
c.logger.Log("err", err, "ref", up.ref)
}
return
}
c.Lock()
successCount++
if entry.ExcludedReason == "" {
result[upCopy.ref.Tag] = entry.Info
}
c.Unlock()
}()
}

```

Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.

commit ID: 34c3f2f5acfdbb197a3783b3cfd1dfab66a1ecc0

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.