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

khoshhalbot/ok: rssbot/rssbot/rssbot.go; 53 LoC

Open
#13,517 0 comments 0 reactions 0 assignees View on GitHub
fresh medium
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [khoshhalbot/ok](https://www.github.com/khoshhalbot/ok) at [rssbot/rssbot/rssbot.go](https://github.com/khoshhalbot/ok/blob/5dc50e98b75b93586b3996f8a0600d06f98a22b6/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/khoshhalbot/ok/blob/5dc50e98b75b93586b3996f8a0600d06f98a22b6/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: 5dc50e98b75b93586b3996f8a0600d06f98a22b6

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.