github-vet / github-vet/rangeloop-pointer-findings
LSvKing/centipede: centipede/centipede.go; 58 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [LSvKing/centipede](https://www.github.com/LSvKing/centipede) at [centipede/centipede.go](https://github.com/LSvKing/centipede/blob/5ba0be8e08116756e8a43f2235b425749d499a27/centipede/centipede.go#L222-L279)
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 crawlerChan used in defer or goroutine at line 275
[Click here to see the code in its original context.](https://github.com/LSvKing/centipede/blob/5ba0be8e08116756e8a43f2235b425749d499a27/centipede/centipede.go#L222-L279)
Click here to show the 58 line(s) of Go which triggered the analyzer.
```go
for crawlerChan := range centipede.CrawlerJob {
ctx, _ := context.WithCancel(context.Background())
limiter := rate.NewLimiter(crawlerChan.CrawlerEr.Option().Limit, 1024)
go func() {
limiter.Wait(ctx)
req, err := centipede.Scheduler.Poll()
fmt.Println(req)
if err != nil {
time.Sleep(1 * time.Second)
}
if req.ReTry > 3 {
Log.Errorln("已到达最大重试次数,抛弃", req)
}
if resp, err := centipede.Downloader.Download(req); err != nil {
Log.WithField("type", "downloadReTry").WithError(err).Error("下载重试")
if req.ReTry < 4 {
req.ReTry += 1
centipede.Scheduler.Push(req)
} else {
Log.WithField("type", "downloadError").WithError(err).Error("重试失败")
}
} else {
defer func() {
if p := recover(); p != nil {
Log.WithField("trace", string(debug.Stack())).Fatalf("蜘蛛异常错误 error: %v", p)
}
}()
Log.Debugln("get finsh")
//通过反射执行 回调函数
params := make([]reflect.Value, 0)
//取 resp 参数放入执行参数
params = append(params, reflect.ValueOf(resp))
//如果回调请求设置了 自定义参数 加入自定义参数到执行参数
if req.CallParams != nil {
params = append(params, reflect.ValueOf(req.CallParams))
}
//通过反射执行函数
reflect.ValueOf(crawlerChan.CrawlerEr).MethodByName(req.Callback).Call(params)
}
}()
}
```
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: 5ba0be8e08116756e8a43f2235b425749d499a27
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.