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

hscells/groove: pipeline.go; 69 LoC

Open
#7,663 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 [hscells/groove](https://www.github.com/hscells/groove) at [pipeline.go](https://github.com/hscells/groove/blob/8c20ac6a00a1c672d22742c32e84ec993b088fb3/pipeline.go#L387-L455)

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 q used in defer or goroutine at line 391

[Click here to see the code in its original context.](https://github.com/hscells/groove/blob/8c20ac6a00a1c672d22742c32e84ec993b088fb3/pipeline.go#L387-L455)

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

```go
for i, q := range measurementQueries {
sem <- true
go func(idx int, query pipeline.Query) {
defer func() { <-sem }()
if _, ok := r.Results[q.Topic]; ok {
log.Printf("already completed topic %v, so skipping it\n", q.Topic)
return
}
if loghw {
_ = p.Headway.Send(float64(i)+1, float64(len(measurementQueries)), "EV."+hwName, fmt.Sprintf("%s", query.Topic))
}
log.Printf("starting topic %v\n", query.Topic)

tree, cache, err := combinator.NewLogicalTree(query, p.StatisticsSource, p.QueryCache)
if err != nil {
c <- pipeline.Result{
Topic: query.Topic,
Error: err,
Type: pipeline.Error,
}
return
}
docIds := tree.Documents(cache)
if err != nil {
c <- pipeline.Result{
Topic: query.Topic,
Error: err,
Type: pipeline.Error,
}
return
}
trecResults := docIds.Results(query, query.Name)
//trecResults, err := p.StatisticsSource.Execute(query, p.StatisticsSource.SearchOptions())
//if err != nil {
// if loghw {
// _ = p.Headway.Message(err.Error())
// _ = p.Headway.Send(float64(i), float64(len(measurementQueries)), hwName, err.Error())
// }
// panic(err)
//}

// Set the evaluation results.
if len(p.Evaluations) > 0 {
c <- pipeline.Result{
Topic: query.Topic,
Evaluations: eval.Evaluate(p.Evaluations, &trecResults, p.EvaluationFormatters.EvaluationQrels, query.Topic),
Type: pipeline.Evaluation,
}
}

// MeasurementOutput the trec results.
if len(p.OutputTrec.Path) > 0 {
c <- pipeline.Result{
Topic: query.Topic,
TrecResults: &trecResults,
Type: pipeline.TrecResult,
}
}

// Send the transformation through the channel.
c <- pipeline.Result{
Topic: q.Topic,
Transformation: pipeline.QueryResult{Name: query.Name, Topic: query.Topic, Transformation: query.Query},
Type: pipeline.Transformation,
}

log.Printf("completed topic %v\n", query.Topic)
}(i, q)
}

```

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: 8c20ac6a00a1c672d22742c32e84ec993b088fb3

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.