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

distr1/distri: internal/batch/batch.go; 52 LoC

Open
#6,982 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 [distr1/distri](https://www.github.com/distr1/distri) at [internal/batch/batch.go](https://github.com/distr1/distri/blob/1cb2853c809c2a451d6c9a7dea4c8ea62ea47d5b/internal/batch/batch.go#L388-L439)

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 n used in defer or goroutine at line 403

[Click here to see the code in its original context.](https://github.com/distr1/distri/blob/1cb2853c809c2a451d6c9a7dea4c8ea62ea47d5b/internal/batch/batch.go#L388-L439)

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

```go
for n := range work {
if err := ctx.Err(); err != nil {
return err
}
// Kick off the build
{
ev := trace.Event("build "+n.pkg, i)
ev.Type = "B" // begin
ev.Done()
}
s.updateStatus(i+1, "building "+n.pkg)
start := time.Now()
result := make(chan error)
if s.simulate {
go func() {
if !s.buildDry(ctx, n.pkg) {
result <- xerrors.Errorf("simulate intentionally failed")
} else {
result <- nil
}
}()
} else {
go func() {
err := s.build(ctx, n.pkg)
result <- err
}()
}

// Wait for the build to complete while updating status
var err error
Build:
for {
select {
case err = <-result:
break Build
case <-ticker.C:
s.updateStatus(i+1, fmt.Sprintf("building %s since %v", n.pkg, time.Since(start)))
}
}

select {
case done <- buildResult{node: n, err: err}:
case <-ctx.Done():
return ctx.Err()
}
{
ev := trace.Event("build "+n.pkg, i)
ev.Type = "E" // end
ev.Done()
}
s.updateStatus(i+1, "idle")
}

```

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: 1cb2853c809c2a451d6c9a7dea4c8ea62ea47d5b

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.