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

yougaUsth/yespider-go: spider/parsers/base.go; 25 LoC

Open
#13,084 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 [yougaUsth/yespider-go](https://www.github.com/yougaUsth/yespider-go) at [spider/parsers/base.go](https://github.com/yougaUsth/yespider-go/blob/a3fa7ba1270bc189e3f0d6b7a5ecd63f0679b04f/spider/parsers/base.go#L66-L90)

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 xUrl used in defer or goroutine at line 79

[Click here to see the code in its original context.](https://github.com/yougaUsth/yespider-go/blob/a3fa7ba1270bc189e3f0d6b7a5ecd63f0679b04f/spider/parsers/base.go#L66-L90)

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

```go
for _, xUrl := range p.ToDoList {
go func() {
// 解析Article 详细配置
for _, articleConf := range p.ArticleList {
c := colly.NewCollector(colly.MaxDepth(1))

//TODO: Article parser
c.OnHTML(articleConf.Xpath, func(element *colly.HTMLElement) {
articleText := element.Text
fmt.Print(articleText)
})

c.OnRequest(func(request *colly.Request) {
fmt.Println("Visiting", xUrl)
})

err := c.Visit(xUrl)
if err != nil {
//log.Fatalf("Raise a exception when visit %v", err)
fmt.Printf("Raise a exception when visit %v", err)
}
}
}()
time.Sleep(5 * time.Second)
}

```

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: a3fa7ba1270bc189e3f0d6b7a5ecd63f0679b04f

Contributor guide

No contributing guide indexed for this repository

Research direction

Read spider/parsers/base.go lines 66-90 at commit a3fa7ba1270bc189e3f0d6b7a5ecd63f0679b04f, focusing on the range loop, goroutine, and xUrl use. Decide whether the analyzer finding represents a bug, mitigation, or desirable behavior, then leave the corresponding reaction on this issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
tooling
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.