github-vet / github-vet/rangeloop-pointer-findings
gopeak/ueli: hub/tick.go; 56 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [gopeak/ueli](https://www.github.com/gopeak/ueli) at [hub/tick.go](https://github.com/gopeak/ueli/blob/9375df0df97ce4abef7defedf905d9f14c60dc87/hub/tick.go#L86-L141)
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 now used in defer or goroutine at line 98
[Click here to see the code in its original context.](https://github.com/gopeak/ueli/blob/9375df0df97ce4abef7defedf905d9f14c60dc87/hub/tick.go#L86-L141)
Click here to show the 56 line(s) of Go which triggered the analyzer.
```go
for now := range timer {
//fmt.Println("now", now)
ch_success := make(chan string, 0)
for _, data := range global.Config.WorkerServer.Servers {
go func(data []interface{}) {
worker_host, _ := data[0].(string)
worker_port_str, _ := data[1].(string)
ip_port := worker_host + ":" + worker_port_str
//fmt.Println("tcpAddr: ",index," ", ip_port)
conn, err_req := net.DialTimeout("tcp", ip_port, 5*time.Second)
if err_req != nil {
golog.Error("检测到 workerserver:", ip_port, " 连接异常!", now)
for i, addr := range global.WorkerServers {
if addr == ip_port {
global.WorkerServers = append(global.WorkerServers[:i], global.WorkerServers[i+1:]...)
}
}
ch_success <- ip_port + err_req.Error()
} else {
exist := false
for _, addr := range global.WorkerServers {
if addr == ip_port {
exist = true
break
}
}
if !exist {
global.WorkerServers = append(global.WorkerServers, ip_port)
}
ch_success <- ip_port + "ok"
}
//fmt.Println("result: ", ip_port, " ok")
//req_str:= fmt.Sprintf("%d||%s||%s||%d||%s\n", protocol.TypePing, "Ping", "", 0, "")
//conn.Write([]byte(req_str))
conn.Close()
}(data)
}
sum := 0
for i := 0; i < len(global.Config.WorkerServer.Servers)+1; i++ {
select {
case <-ch_success:
//fmt.Println("recv_result:", r)
sum++
if sum == len(global.Config.WorkerServer.Servers) {
break
}
default:
//fmt.Printf(".")
time.Sleep(10 * time.Millisecond)
}
}
//fmt.Println("sum:", sum)
}
```
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: 9375df0df97ce4abef7defedf905d9f14c60dc87
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with hub/tick.go lines 86-141 at commit 9375df0df97ce4abef7defedf905d9f14c60dc87, focusing on the range variables used by the goroutine and the analyzer warning at line 98. Trace whether the reported behavior is present, then classify the finding as Bug, Mitigated, or Desirable Behavior and leave the corresponding reaction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend, networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100