github-vet / github-vet/rangeloop-pointer-findings
cloud-bulldozer/kube-burner: pkg/burner/delete.go; 50 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [cloud-bulldozer/kube-burner](https://www.github.com/cloud-bulldozer/kube-burner) at [pkg/burner/delete.go](https://github.com/cloud-bulldozer/kube-burner/blob/87e28d59cb4eccff32b19cbbb4ceabc4d8fa2017/pkg/burner/delete.go#L70-L119)
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 obj used in defer or goroutine at line 92
[Click here to see the code in its original context.](https://github.com/cloud-bulldozer/kube-burner/blob/87e28d59cb4eccff32b19cbbb4ceabc4d8fa2017/pkg/burner/delete.go#L70-L119)
Click here to show the 50 line(s) of Go which triggered the analyzer.
```go
for _, obj := range ex.objects {
labelSelector := labels.Set(obj.labelSelector).String()
listOptions := metav1.ListOptions{
LabelSelector: labelSelector,
}
err = RetryWithExponentialBackOff(func() (done bool, err error) {
resp, err = dynamicClient.Resource(obj.gvr).List(context.TODO(), listOptions)
if err != nil {
log.Errorf("Error found listing %s labeled with %s: %s", obj.gvr.Resource, labelSelector, err)
return false, nil
}
return true, nil
})
if err != nil {
continue
}
log.Infof("Found %d %s with selector %s", len(resp.Items), obj.gvr.Resource, labelSelector)
for _, item := range resp.Items {
wg.Add(1)
go func(item unstructured.Unstructured) {
defer wg.Done()
ex.limiter.Wait(context.TODO())
err := dynamicClient.Resource(obj.gvr).Namespace(item.GetNamespace()).Delete(context.TODO(), item.GetName(), metav1.DeleteOptions{})
if err != nil {
log.Errorf("Error found removing %s %s: %s", item.GetKind(), item.GetName(), err)
} else {
ns := item.GetNamespace()
if ns != "" {
log.Infof("Removing %s/%s from namespace %s", item.GetKind(), item.GetName(), ns)
} else {
log.Infof("Removing %s/%s", item.GetKind(), item.GetName())
}
}
}(item)
}
if ex.Config.WaitForDeletion {
wg.Wait()
wait.PollImmediateInfinite(2*time.Second, func() (bool, error) {
resp, err = dynamicClient.Resource(obj.gvr).List(context.TODO(), listOptions)
if err != nil {
return false, err
}
if len(resp.Items) > 0 {
log.Infof("Waiting for %d %s labeled with %s to be deleted", len(resp.Items), obj.gvr.Resource, labelSelector)
return false, nil
}
return true, nil
})
}
}
```
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: 87e28d59cb4eccff32b19cbbb4ceabc4d8fa2017
Contributor guide
No contributing guide indexed for this repository
Research direction
Read pkg/burner/delete.go at lines 70-119 in commit 87e28d59cb4eccff32b19cbbb4ceabc4d8fa2017, focusing on the goroutine and the surrounding range loops. Check whether the captured obj can refer to a different loop value when deletion runs. Done means classifying the analyzer finding as Bug, Mitigated, or Desirable Behavior with a reaction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- infrastructure
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100