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

rai-project/dlframework: framework/cmd/server/predict_urls.go; 64 LoC

Open
#8,139 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 [rai-project/dlframework](https://www.github.com/rai-project/dlframework) at [framework/cmd/server/predict_urls.go](https://github.com/rai-project/dlframework/blob/4aaa12cfa5874a785cbe70a2bc8a849472c7bc95/framework/cmd/server/predict_urls.go#L348-L411)

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 part used in defer or goroutine at line 352

[Click here to see the code in its original context.](https://github.com/rai-project/dlframework/blob/4aaa12cfa5874a785cbe70a2bc8a849472c7bc95/framework/cmd/server/predict_urls.go#L348-L411)

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

```go
for ii, part := range urlParts[:numUrlParts] {
input := make(chan interface{}, DefaultChannelBuffer)
go func() {
defer close(input)
for _, url := range part {
id := uuid.NewV4()
lbl := steps.NewIDWrapper(id, url)
partlabels[lbl.GetID()] = "" // no label for the input url
input <- lbl
}
}()

evaluateBatchSpan, evaluateBatchCtx := tracer.StartSpanFromContext(
ctx,
tracer.APPLICATION_TRACE,
"evaluate_batch",
opentracing.Tags{
"batch_index": ii,
},
)

opts := []pipeline.Option{pipeline.ChannelBuffer(DefaultChannelBuffer)}
if tracePreprocess == true {
opts = append(opts, pipeline.Context(evaluateBatchCtx))
}
output := pipeline.New(opts...).
Then(steps.NewReadURL()).
Then(steps.NewReadImage(preprocessOptions)).
Then(steps.NewPreprocessImage(preprocessOptions)).
Run(input)

var images []interface{}
for out := range output {
images = append(images, out)
}

imageParts := dl.Partition(images, batchSize)

input = make(chan interface{}, DefaultChannelBuffer)
go func() {
defer close(input)
for _, p := range imageParts {
input <- p
}
}()

output = pipeline.New(pipeline.Context(evaluateBatchCtx), pipeline.ChannelBuffer(DefaultChannelBuffer)).
Then(steps.NewPredict(predictor)).
Run(input)

inferenceProgress.Add(batchSize)

for o := range output {
if err, ok := o.(error); ok && failOnFirstError {
//inferenceProgress.FinishPrint("inference halted")
inferenceProgress.Finish()

log.WithError(err).Error("encountered an error while performing inference")
os.Exit(-1)
}
outputs <- o
}
evaluateBatchSpan.Finish()
}

```

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: 4aaa12cfa5874a785cbe70a2bc8a849472c7bc95

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.