github-vet / github-vet/rangeloop-pointer-findings
go-vela/pkg-executor: executor/linux/secret.go; 64 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [go-vela/pkg-executor](https://www.github.com/go-vela/pkg-executor) at [executor/linux/secret.go](https://github.com/go-vela/pkg-executor/blob/c434ad8c22a028d921cb97d3ec9c4721cacb47a3/executor/linux/secret.go#L202-L265)
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 secret used in defer or goroutine at line 223
[Click here to see the code in its original context.](https://github.com/go-vela/pkg-executor/blob/c434ad8c22a028d921cb97d3ec9c4721cacb47a3/executor/linux/secret.go#L202-L265)
Click here to show the 64 line(s) of Go which triggered the analyzer.
```go
for _, secret := range *p {
// skip over non-plugin secrets
if secret.Origin.Empty() {
continue
}
// update engine logger with secret metadata
//
// https://pkg.go.dev/github.com/sirupsen/logrus?tab=doc#Entry.WithField
logger := s.client.logger.WithField("secret", secret.Origin.Name)
logger.Debug("running container")
// run the runtime container
err := s.client.Runtime.RunContainer(ctx, secret.Origin, s.client.pipeline)
if err != nil {
return err
}
go func() {
logger.Debug("stream logs for container")
// stream logs from container
err = s.client.secret.stream(ctx, secret.Origin)
if err != nil {
logger.Error(err)
}
}()
logger.Debug("waiting for container")
// wait for the runtime container
err = s.client.Runtime.WaitContainer(ctx, secret.Origin)
if err != nil {
return err
}
logger.Debug("inspecting container")
// inspect the runtime container
err = s.client.Runtime.InspectContainer(ctx, secret.Origin)
if err != nil {
return err
}
// check the step exit code
if secret.Origin.ExitCode != 0 {
// check if we ignore step failures
if !secret.Origin.Ruleset.Continue {
// set build status to failure
s.client.build.SetStatus(constants.StatusFailure)
}
// update the step fields
init.SetExitCode(secret.Origin.ExitCode)
init.SetStatus(constants.StatusFailure)
return fmt.Errorf("%s container exited with non-zero code", secret.Origin.Name)
}
// send API call to update the build
//
// https://pkg.go.dev/github.com/go-vela/sdk-go/vela?tab=doc#StepService.Update
_, _, err = s.client.Vela.Step.Update(r.GetOrg(), r.GetName(), s.client.build.GetNumber(), init)
if err != nil {
s.client.logger.Errorf("unable to upload init state: %v", err)
}
}
```
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: c434ad8c22a028d921cb97d3ec9c4721cacb47a3
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.