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

ovh/utask: engine/engine.go; 58 LoC

Open
#6,060 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 [ovh/utask](https://www.github.com/ovh/utask) at [engine/engine.go](https://github.com/ovh/utask/blob/31215cdcfa1135ac36014465f36931b88050ed2c/engine/engine.go#L636-L693)

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 s used in defer or goroutine at line 676

[Click here to see the code in its original context.](https://github.com/ovh/utask/blob/31215cdcfa1135ac36014465f36931b88050ed2c/engine/engine.go#L636-L693)

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

```go
for name, s := range av {
// prepare step
s.Name = name
if s.ForEach != "" { // loop step
switch s.State {
case step.StateTODO:
expanded++
expandStep(s, res)
expandedSteps = append(expandedSteps, s.ChildrenSteps...)
case step.StateToRetry:
// attempt contracting step, clean up any children steps
// any available children have been ignored by availableSteps()
if s.ChildrenSteps != nil && len(s.ChildrenSteps) > 0 {
contractStep(s, res)
s.Output = nil
} else {
expanded++
expandStep(s, res)
expandedSteps = append(expandedSteps, s.ChildrenSteps...)
}
case step.StateExpanded:
contractStep(s, res)
res.SetStepState(s.Name, step.StateDone)
default:
// if the ForEach task is in another state, we do nothing, but need to return the step in the stepChan
// otherwise the task will wait infinitely for this step
}

// after expanding or contracting, need to check if the step didn't turn into a bad state (FatalError, ServerError, ...) during the operation
// if so, it should be ignored during next runAvailableSteps (as we did expanded++)
switch s.State {
case step.StateTODO, step.StateToRetry, step.StateExpanded:
// those states could lead the step to be reconsidered on the next runAvailableSteps if the children run fast enough (and not have to wait for the next resolution.Run)
default:
// other states are errors, we should stop considering this step as eligible during this run
executedSteps[s.Name] = true
}
// rebuild step dependency tree to include generated loop steps
res.BuildStepTree()
commit(dbp, res, nil)
go func() { stepChan <- s }()
} else { // regular step
s.ResultValidate = jsonschema.Validator(s.Name, s.Schema)

// skip prerun
// TODO fixme, ugly
// juggling with STATE_AFTERRUN_ERROR should probably only be inside step pkg
if s.State != step.StateAfterrunError {
res.SetStepState(s.Name, step.StateRunning)
step.PreRun(s, res.Values, resolutionStateSetter(res, preRunModifiedSteps), executedSteps)
commit(dbp, res, nil)
}

// run
stepCopy := *s
step.Run(&stepCopy, res.BaseConfigurations, res.Values, stepChan, wg, shutdownCtx)
}
}

```

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: 31215cdcfa1135ac36014465f36931b88050ed2c

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.