github-vet / github-vet/rangeloop-pointer-findings
netwayfind/cp-scoring: server/server.go; 36 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [netwayfind/cp-scoring](https://www.github.com/netwayfind/cp-scoring) at [server/server.go](https://github.com/netwayfind/cp-scoring/blob/4637ade4e5cdde3a4cfc7a2914929f18a3ec0832/server/server.go#L1903-L1938)
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 hostToken used in defer or goroutine at line 1912
[Click here to see the code in its original context.](https://github.com/netwayfind/cp-scoring/blob/4637ade4e5cdde3a4cfc7a2914929f18a3ec0832/server/server.go#L1903-L1938)
Click here to show the 36 line(s) of Go which triggered the analyzer.
```go
for i, hostToken := range hostTokens {
if firstHostToken {
firstHostToken = false
} else {
w.Write([]byte(","))
}
out := make(chan processing.DocumentDiff)
w.Write([]byte(fmt.Sprintf("\"%d - %s\": [", i, hostnames[hostToken])))
go func() {
err := theServer.backingStore.SelectScenarioReportDiffs(scenarioID, hostToken, timeStart, timeEnd, out)
if err != nil {
msg := "ERROR: cannot retrieve report diffs;"
log.Println(msg, err)
http.Error(w, msg, http.StatusInternalServerError)
return
}
}()
firstOut := true
for diff := range out {
if firstOut {
firstOut = false
} else {
w.Write([]byte(","))
}
b, err := json.Marshal(diff)
if err != nil {
msg := "ERROR: cannot marshall report diffs;"
log.Println(msg, err)
http.Error(w, msg, http.StatusInternalServerError)
return
}
w.Write(b)
}
w.Write([]byte("]"))
}
```
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: 4637ade4e5cdde3a4cfc7a2914929f18a3ec0832
Contributor guide
No contributing guide indexed for this repository
Research direction
Review server/server.go around lines 1903-1938, especially the range over hostTokens and the goroutine using hostToken. Check the linked commit context and the analyzer description, then classify the finding as Bug, Mitigated, or Desirable Behavior by leaving the corresponding reaction. Done means one classification reaction has been added.
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
- Clearly specified
- Newbie friendliness
- 45/100