github-vet / github-vet/rangeloop-pointer-findings
AdRoll/batchiepatchie: jobs/scaler.go; 60 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [AdRoll/batchiepatchie](https://www.github.com/AdRoll/batchiepatchie) at [jobs/scaler.go](https://github.com/AdRoll/batchiepatchie/blob/e86e28f43218f578d6b838b50a888b8f97ddd552/jobs/scaler.go#L88-L147)
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.
> reference to ce is reassigned at line 92
[Click here to see the code in its original context.](https://github.com/AdRoll/batchiepatchie/blob/e86e28f43218f578d6b838b50a888b8f97ddd552/jobs/scaler.go#L88-L147)
Click here to show the 60 line(s) of Go which triggered the analyzer.
```go
for ce, wanted := range wanted_vcpus_by_ce {
log.Info("Wanted vcpus in compute environment ", ce, ": ", wanted)
ces := make([]*string, 1)
ces[0] = &ce
out, err := awsclients.Batch.DescribeComputeEnvironments(&batch.DescribeComputeEnvironmentsInput{
ComputeEnvironments: ces,
})
if err != nil {
log.Warning("DescribeComputeEnvironments failed on compute environment ", ce, ": ", err)
continue
}
if len(out.ComputeEnvironments) != 1 {
log.Warning("Skipping compute environment ", ce, ", no information from DescribeComputeEnvironments")
continue
}
detail := out.ComputeEnvironments[0]
if detail.Status == nil || detail.State == nil || *detail.Status != "VALID" || *detail.State != "ENABLED" || detail.ComputeResources == nil {
log.Warning("Not scaling ", ce, " because it's not both VALID and ENABLED.")
continue
}
if detail.ComputeResources.DesiredvCpus == nil {
// I'm not sure if AWS Batch would actually return nil here ever but it's allowed by types :shruggie:
// Let's not crash if it's nil for whatever reason
log.Warning("Not scaling ", ce, " because it has no desired vcpus set.")
continue
}
if detail.ComputeResources.MaxvCpus == nil {
log.Warning("Not scaling ", ce, " because it has no maximum vcpus set.")
continue
}
batch_min_vcpus := *detail.ComputeResources.MinvCpus
batch_max_vcpus := *detail.ComputeResources.MaxvCpus
wanted := wanted
if wanted > batch_max_vcpus {
wanted = batch_max_vcpus
}
update_resources := batch.ComputeResourceUpdate{
MinvCpus: &wanted,
}
// Now for the meat...if the desired vcpus is lower than we would like, we scale up.
if wanted != batch_min_vcpus {
_, err := awsclients.Batch.UpdateComputeEnvironment(&batch.UpdateComputeEnvironmentInput{
ComputeEnvironment: &ce,
ComputeResources: &update_resources,
})
if err != nil {
log.Error("Tried to scale ", ce, " but it failed: ", err)
continue
}
log.Info("Updated job queue min vcpus in ", ce, " from ", batch_min_vcpus, " to ", wanted)
}
}
```
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: e86e28f43218f578d6b838b50a888b8f97ddd552
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.