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

operator-framework/operator-registry: pkg/lib/registry/registry.go; 54 LoC

Open
#15,953 0 comments 0 reactions 0 assignees View on GitHub
fresh medium
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [operator-framework/operator-registry](https://www.github.com/operator-framework/operator-registry) at [pkg/lib/registry/registry.go](https://github.com/operator-framework/operator-registry/blob/b883288704220699151ca7b5e5b4353856ed4964/pkg/lib/registry/registry.go#L142-L195)

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 to used in defer or goroutine at line 174

[Click here to see the code in its original context.](https://github.com/operator-framework/operator-registry/blob/b883288704220699151ca7b5e5b4353856ed4964/pkg/lib/registry/registry.go#L142-L195)

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

```go
for to, from := range unpackedImageMap {
img, err := registry.NewImageInput(to, from)
if err != nil {
return err
}
overwritten, err := querier.GetBundlePathIfExists(ctx, img.Bundle.Name)
if err != nil {
if err == registry.ErrBundleImageNotInDatabase {
continue
}
return err
}
if overwritten != "" {
// get all bundle paths for that package - we will re-add these to regenerate the graph
bundles, err := querier.GetBundlesForPackage(ctx, img.Bundle.Package)
if err != nil {
return err
}
type unpackedImage struct {
to image.Reference
from string
cleanup func()
err error
}
unpacked := make(chan unpackedImage)
for bundle := range bundles {
// parallelize image pulls
go func(bundle registry.BundleKey, img *registry.ImageInput) {
if bundle.CsvName != img.Bundle.Name {
to, from, cleanup, err := unpackImage(ctx, reg, image.SimpleReference(bundle.BundlePath))
unpacked <- unpackedImage{to: to, from: from, cleanup: cleanup, err: err}
} else {
unpacked <- unpackedImage{to: to, from: from, cleanup: func() { return }, err: nil}
}
}(bundle, img)
}
if _, ok := overwriteImageMap[img.Bundle.Package]; !ok {
overwriteImageMap[img.Bundle.Package] = make(map[image.Reference]string, 0)
}
for i := 0; i < len(bundles); i++ {
unpack := <-unpacked
if unpack.err != nil {
return unpack.err
}
overwriteImageMap[img.Bundle.Package][unpack.to] = unpack.from
if _, ok := unpackedImageMap[unpack.to]; ok {
delete(unpackedImageMap, unpack.to)
}
defer unpack.cleanup()
}
} else {
return fmt.Errorf("index add --overwrite-latest is only supported when using bundle images")
}
}

```

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: b883288704220699151ca7b5e5b4353856ed4964

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with pkg/lib/registry/registry.go at lines 142-195 and inspect the goroutine and deferred cleanup around the reported range-loop variable. Determine whether the analyzer finding represents a real bug, mitigated behavior, or desirable behavior, then leave the corresponding reaction on the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.