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

devopsxp/xp: roles/factory.go; 25 LoC

Open
#14,568 0 comments 0 reactions 0 assignees View on GitHub
fresh small
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [devopsxp/xp](https://www.github.com/devopsxp/xp) at [roles/factory.go](https://github.com/devopsxp/xp/blob/5953dcc7f7a42e5a6592809dfe79b70c9a01054f/roles/factory.go#L144-L168)

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 n used in defer or goroutine at line 152

[Click here to see the code in its original context.](https://github.com/devopsxp/xp/blob/5953dcc7f7a42e5a6592809dfe79b70c9a01054f/roles/factory.go#L144-L168)

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

```go
for n, config := range args.configs {
// config stage 全局上下文context
ctx := context.Background()
timeout := time.Duration(args.timeout) * time.Second
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()

go func() {
ch <- execConfig(args, n, config)
}()

select {
case err := <-ch:
if err != nil {
return err
}
case <-ctx.Done():
log.Errorf("超时 %d秒: 主机 %s Stage %s %v", args.timeout, args.host, args.stage, config)
// 超时是退出还是继续下一步?
if args.timeoutexit {
log.Error("超时退出")
os.Exit(1)
}
}
}

```

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: 5953dcc7f7a42e5a6592809dfe79b70c9a01054f

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.