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

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

Open
#12,463 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

Research direction

Start with pteron.go lines 51-73 and inspect how the range variable j is used inside the goroutine and timeout handling. Run the project's available tests or reproduce the job-processing behavior to determine whether iterations can use the wrong job value. Done means classifying the finding as Bug, Mitigated, or Desirable Behavior with evidence.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.