github-vet / github-vet/rangeloop-pointer-findings
pipe-cd/pipe: pkg/app/piped/controller/scheduler.go; 80 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [pipe-cd/pipe](https://www.github.com/pipe-cd/pipe) at [pkg/app/piped/controller/scheduler.go](https://github.com/pipe-cd/pipe/blob/64dbe76f405e176aee9a7fca22acc5023b0c26eb/pkg/app/piped/controller/scheduler.go#L273-L352)
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 ps used in defer or goroutine at line 302
[Click here to see the code in its original context.](https://github.com/pipe-cd/pipe/blob/64dbe76f405e176aee9a7fca22acc5023b0c26eb/pkg/app/piped/controller/scheduler.go#L273-L352)
Click here to show the 80 line(s) of Go which triggered the analyzer.
```go
for i, ps := range s.deployment.Stages {
lastStage = s.deployment.Stages[i]
if ps.Status == model.StageStatus_STAGE_SUCCESS {
continue
}
if !ps.Visible || ps.Name == model.StageRollback.String() {
continue
}
// This stage is already completed by a previous scheduler.
if ps.Status == model.StageStatus_STAGE_CANCELLED {
deploymentStatus = model.DeploymentStatus_DEPLOYMENT_CANCELLED
statusReason = fmt.Sprintf("Deployment was cancelled while executing stage %s", ps.Id)
break
}
if ps.Status == model.StageStatus_STAGE_FAILURE {
deploymentStatus = model.DeploymentStatus_DEPLOYMENT_FAILURE
statusReason = fmt.Sprintf("Failed while executing stage %s", ps.Id)
break
}
var (
result model.StageStatus
sig, handler = executor.NewStopSignal()
doneCh = make(chan struct{})
)
go func() {
result = s.executeStage(sig, *ps, func(in executor.Input) (executor.Executor, bool) {
return s.executorRegistry.Executor(model.Stage(ps.Name), in)
})
close(doneCh)
}()
select {
case <-ctx.Done():
handler.Terminate()
<-doneCh
case <-timer.C:
handler.Timeout()
<-doneCh
case cmd := <-s.cancelledCh:
if cmd != nil {
cancelCommand = cmd
cancelCommander = cmd.Commander
handler.Cancel()
<-doneCh
}
case <-doneCh:
break
}
// If all operations of the stage were completed successfully
// go the next stage to handle.
if result == model.StageStatus_STAGE_SUCCESS {
continue
}
sigType := sig.Signal()
// The deployment was cancelled by a web user.
if sigType == executor.StopSignalCancel {
deploymentStatus = model.DeploymentStatus_DEPLOYMENT_CANCELLED
statusReason = fmt.Sprintf("Deployment was cancelled by %s while executing stage %s", cancelCommander, ps.Id)
break
}
// The stage was failed but not caused by the stop signal.
if result == model.StageStatus_STAGE_FAILURE && sigType == executor.StopSignalNone {
deploymentStatus = model.DeploymentStatus_DEPLOYMENT_FAILURE
statusReason = fmt.Sprintf("Failed while executing stage %s", ps.Id)
break
}
return 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: 64dbe76f405e176aee9a7fca22acc5023b0c26eb
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.