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

alpha-team/at-download: rssbot/rssbot/rssbot.go; 48 LoC

Open
#6,283 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 [alpha-team/at-download](https://www.github.com/alpha-team/at-download) at [rssbot/rssbot/rssbot.go](https://github.com/alpha-team/at-download/blob/af87459b9c35616eff238c54dec46865a60d9203/rssbot/rssbot/rssbot.go#L143-L190)

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 183

[Click here to see the code in its original context.](https://github.com/alpha-team/at-download/blob/af87459b9c35616eff238c54dec46865a60d9203/rssbot/rssbot/rssbot.go#L143-L190)

Click here to show the 48 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.Printf("Removing url %s\n", 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: af87459b9c35616eff238c54dec46865a60d9203

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.