github-vet / github-vet/rangeloop-pointer-findings
toukii/httpvf: vf.go; 107 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [toukii/httpvf](https://www.github.com/toukii/httpvf) at [vf.go](https://github.com/toukii/httpvf/blob/1b46f5d100692806fef8ed42d3f2b61cbce525da/vf.go#L132-L238)
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 it used in defer or goroutine at line 155
[Click here to see the code in its original context.](https://github.com/toukii/httpvf/blob/1b46f5d100692806fef8ed42d3f2b61cbce525da/vf.go#L132-L238)
Click here to show the 107 line(s) of Go which triggered the analyzer.
```go
for _, it := range reqs {
it.Prapare()
// fmt.Println("***", it.URL)
if it.Interval > 0 {
ticker := time.NewTicker(time.Duration(it.Interval * 1e6))
tickerMap[it.MapKey()] = ticker
// fmt.Println(it.MapKey(), it.Interval)
}
runtineMap[it.MapKey()] = make(chan struct{}, it.Runtine)
wg.Add(1)
if isSync {
// fmt.Println("[sync GO]", it.URL)
i := 0
cost := 0
var tps string
logs := make([]*Log, 0, 64)
index := make(chan struct{}, 1)
itWg := sync.WaitGroup{}
for i = 0; i < it.N; {
itWg.Add(1)
index <- struct{}{}
i++
go func() {
runtineMap[it.MapKey()] <- struct{}{}
msg := verify(it)
cost += msg.Req.Resp.RealCost
logs = append(logs, msg.Logs()...)
/*if i >= it.N {
fmt.Println()
if i>0{
tps += fmt.Sprint("avg cost: ", cost/i, " ms")
}else{
tps += fmt.Sprint("avg cost: ", cost, " ms")
}
msg = newMsg(it)
msg.Append(CONCLUSION, tps)
msg.AppendLogs(logs)
fmt.Println(msg)
}*/
<-runtineMap[it.MapKey()]
verifys(it.Then, it.Sync)
itWg.Done()
}()
<-index
if ticker, ok := tickerMap[it.MapKey()]; it.Interval > 0 && ok {
<-ticker.C
}
}
itWg.Wait()
////////////////////////////
fmt.Println()
if i > 0 {
tps += fmt.Sprint("avg cost: ", cost/i, " ms")
} else {
tps += fmt.Sprint("avg cost: ", cost, " ms")
}
msg := newMsg(it)
msg.Append(CONCLUSION, tps)
msg.AppendLogs(logs)
fmt.Println(msg)
////////////////////////////
wg.Done()
} else {
go func(it *Req) {
// fmt.Println("[GO]", it.URL)
i := 0
cost := 0
var tps string
logs := make([]*Log, 0, 64)
index := make(chan struct{}, 1)
itWg := sync.WaitGroup{}
for i = 0; i < it.N; {
itWg.Add(1)
index <- struct{}{}
i++
go func() {
runtineMap[it.MapKey()] <- struct{}{}
msg := verify(it)
cost += msg.Req.Resp.RealCost
logs = append(logs, msg.Logs()...)
<-runtineMap[it.MapKey()]
verifys(it.Then, it.Sync)
itWg.Done()
}()
<-index
if ticker, ok := tickerMap[it.MapKey()]; it.Interval > 0 && ok {
<-ticker.C
}
}
itWg.Wait()
////////////////////////////
fmt.Println()
if i > 0 {
tps += fmt.Sprint("avg cost: ", cost/i, " ms")
} else {
tps += fmt.Sprint("avg cost: ", cost, " ms")
}
msg := newMsg(it)
msg.Append(CONCLUSION, tps)
msg.AppendLogs(logs)
fmt.Println(msg)
////////////////////////////
wg.Done()
}(it)
}
}
```
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: 1b46f5d100692806fef8ed42d3f2b61cbce525da
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.