github-vet / github-vet/rangeloop-pointer-findings
gopeak/ueligo: 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/ueligo](https://www.github.com/gopeak/ueligo) at [hub/tick.go](https://github.com/gopeak/ueligo/blob/bd582d3aa2978f703f95d9bbff7881b2d5efdbe0/hub/tick.go#L83-L138)
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 95
[Click here to see the code in its original context.](https://github.com/gopeak/ueligo/blob/bd582d3aa2978f703f95d9bbff7881b2d5efdbe0/hub/tick.go#L83-L138)
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.ToWorker.Servers {
go func(data []string) {
worker_host := data[0]
worker_port_str := data[1]
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.ToWorker.Servers)+1; i++ {
select {
case <-ch_success:
//fmt.Println("recv_result:", r)
sum++
if sum == len(global.Config.ToWorker.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: bd582d3aa2978f703f95d9bbff7881b2d5efdbe0
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.