github-vet / github-vet/rangeloop-pointer-findings
IBM/multi-cluster-app-dispatcher: pkg/controller/queuejob/queuejob_controller.go; 46 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [IBM/multi-cluster-app-dispatcher](https://www.github.com/IBM/multi-cluster-app-dispatcher) at [pkg/controller/queuejob/queuejob_controller.go](https://github.com/IBM/multi-cluster-app-dispatcher/blob/a144c64b96849c4c651d88d52d1b3f559c2a7eaa/pkg/controller/queuejob/queuejob_controller.go#L349-L394)
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 ts used in defer or goroutine at line 376
[Click here to see the code in its original context.](https://github.com/IBM/multi-cluster-app-dispatcher/blob/a144c64b96849c4c651d88d52d1b3f559c2a7eaa/pkg/controller/queuejob/queuejob_controller.go#L349-L394)
Click here to show the 46 line(s) of Go which triggered the analyzer.
```go
for _, ts := range qj.Spec.TaskSpecs {
replicas := ts.Replicas
name := ts.Template.Name
running := int32(filterPods(pods[name], v1.PodRunning))
pending := int32(filterPods(pods[name], v1.PodPending))
succeeded := int32(filterPods(pods[name], v1.PodSucceeded))
failed := int32(filterPods(pods[name], v1.PodFailed))
runningSum += running
pendingSum += pending
succeededSum += succeeded
failedSum += failed
glog.V(3).Infof("There are %d pods of QueueJob %s (%s): replicas %d, pending %d, running %d, succeeded %d, failed %d",
len(pods), qj.Name, name, replicas, pending, running, succeeded, failed)
// Create pod if necessary
if diff := replicas - pending - running - succeeded; diff > 0 {
glog.V(3).Infof("Try to create %v Pods for QueueJob %v/%v", diff, qj.Namespace, qj.Name)
var errs []error
wait := sync.WaitGroup{}
wait.Add(int(diff))
for i := int32(0); i < diff; i++ {
go func(ix int32) {
defer wait.Done()
newPod := createQueueJobPod(qj, &ts.Template, ix)
_, err := cc.clients.Core().Pods(newPod.Namespace).Create(newPod)
if err != nil {
// Failed to create Pod, wait a moment and then create it again
// This is to ensure all pods under the same QueueJob created
// So gang-scheduling could schedule the QueueJob successfully
glog.Errorf("Failed to create pod %s for QueueJob %s, err %#v",
newPod.Name, qj.Name, err)
errs = append(errs, err)
}
}(i)
}
wait.Wait()
if len(errs) != 0 {
return fmt.Errorf("failed to create %d pods of %d", len(errs), diff)
}
}
}
```
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: a144c64b96849c4c651d88d52d1b3f559c2a7eaa
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.