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

bc-shusson/pteron: pteron.go; 23 LoC

Open
#7,282 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 [bc-shusson/pteron](https://www.github.com/bc-shusson/pteron) at [pteron.go](https://github.com/bc-shusson/pteron/blob/85ad9c74c76a0c24bb3475dfdf3dc0054d15cb9f/pteron.go#L51-L73)

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 j used in defer or goroutine at line 56

[Click here to see the code in its original context.](https://github.com/bc-shusson/pteron/blob/85ad9c74c76a0c24bb3475dfdf3dc0054d15cb9f/pteron.go#L51-L73)

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

```go
for j := range jobs {
<-limiter
// create an anon go routine so we can timeout if the query takes to long
queryJob := make(chan string, 1)
go func() {
fmt.Println("worker", id, "processing job", j)
dsn := getDatabaseDsn(j)
queryJob <- queryDatabase(dsn, query, j)
// queryJob <- queryDatabase(j) //uncomment to run with staight dsns
}()

resultMap := make(map[string]string)
select {
case result := <-queryJob:
resultMap["result"] = result
resultMap["databaseDsn"] = j
results <- resultMap
case <-time.After(time.Second * QUERY_TIMEOUT):
fmt.Println("worker", id, "timed out trying to process ", j)
resultMap[j] = "query timed out"
results <- resultMap
}
}

```

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: 85ad9c74c76a0c24bb3475dfdf3dc0054d15cb9f

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.