github-vet / github-vet/rangeloop-pointer-findings
rockneurotiko/go-bots: rssbot/rssbot/rssbot.go; 53 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [rockneurotiko/go-bots](https://www.github.com/rockneurotiko/go-bots) at [rssbot/rssbot/rssbot.go](https://github.com/rockneurotiko/go-bots/blob/df5513d27dfc3b1ce6f920bdc73a2cf8dfe7446f/rssbot/rssbot/rssbot.go#L143-L195)
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 urlkey used in defer or goroutine at line 188
[Click here to see the code in its original context.](https://github.com/rockneurotiko/go-bots/blob/df5513d27dfc3b1ce6f920bdc73a2cf8dfe7446f/rssbot/rssbot/rssbot.go#L143-L195)
Click here to show the 53 line(s) of Go which triggered the analyzer.
```go
for urlkey := range allrss {
splitted := strings.Split(urlkey, ":")
if len(splitted) != 3 {
continue
}
uri := strings.Join(splitted[1:], ":")
j := i
i++
go func(uri string, firsttime bool) {
n_errors := 0
feed := rss.New(5, true, chanHandler, botItemHandler(bot, firsttime))
// Start calcule by groups, calculate how many sleep before execute
timeofsleep := math.Mod(float64(j), blocks) * nseconds // float64(int(j/module)) * nseconds
start := time.Now()
<-time.After(time.Duration(int(timeofsleep*1000)) * time.Millisecond)
fmt.Printf("%d (%s) started after %v seconds\n", j, uri, time.Since(start))
for {
if err := feed.Fetch(uri, charsetReader); err != nil {
// fmt.Fprintf(os.Stderr, "[e] %s: %s\n", uri, err)
// if isAffordableNetworkError(err) && n_errors < MAX_RETRIES {
if n_errors < MAX_RETRIES {
fmt.Fprintf(os.Stderr, "[e] (%d/%d) %s: %s\n", n_errors, MAX_RETRIES, uri, err)
n_errors++
// <-time.After(time.Duration(feed.SecondsTillUpdate() * 1e9))
<-time.After(time.Duration(MINS_SLEEP) * time.Minute)
continue
} else {
fmt.Fprintf(os.Stderr, "[e] (%d/%d) %s: %s\n", n_errors, MAX_RETRIES, uri, err)
fmt.Fprintf(os.Stderr, "Removing url %s\n", uri)
sendToAll(bot, uri, []NewStruct{
NewStruct{
Text: fmt.Sprintf("Hi! I had too many failures reading the RSS %s and I'm going to remove it, you can subscribe againg using:\n/sub %s", uri, uri),
},
})
cleanBadUrl(uri)
return
}
}
n_errors = 0
if firsttime {
firsttime = false
setRssValue(urlkey, "true")
}
// Every MINS_SLEEP mins
// <-time.After(time.Duration(feed.SecondsTillUpdate() * 1e9))
<-time.After(time.Duration(MINS_SLEEP) * time.Minute)
}
}(uri, true)
}
```
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: df5513d27dfc3b1ce6f920bdc73a2cf8dfe7446f
Contributor guide
No contributing guide indexed for this repository
Research direction
Read rssbot/rssbot/rssbot.go around lines 143-195, focusing on the goroutine and its use of the range-loop variable urlkey. Compare the analyzer report with the code and the project's classification guidance, then classify the finding as Bug, Mitigated, or Desirable Behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100