github-vet / github-vet/rangeloop-pointer-findings
sprawl/sprawl: p2p/p2p.go; 19 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [sprawl/sprawl](https://www.github.com/sprawl/sprawl) at [p2p/p2p.go](https://github.com/sprawl/sprawl/blob/d02a55dbf926f9f1c6f3a57ac7682707fe3c2ff9/p2p/p2p.go#L177-L195)
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 peer used in defer or goroutine at line 188
[Click here to see the code in its original context.](https://github.com/sprawl/sprawl/blob/d02a55dbf926f9f1c6f3a57ac7682707fe3c2ff9/p2p/p2p.go#L177-L195)
Click here to show the 19 line(s) of Go which triggered the analyzer.
```go
for peer := range p2p.peerChan {
if peer.ID == p2p.host.ID() {
p2p.Logger.Debug("Found yourself!")
continue
}
p2p.Logger.Infof("Found a new peer: %s\n", peer.ID)
// Waits on each peerInfo until they are connected or the connection failed
wg.Add(1)
go func(ctx context.Context) {
defer wg.Done()
if err := p2p.host.Connect(ctx, peer); !errors.IsEmpty(err) {
p2p.Logger.Error(errors.E(errors.Op("Connect"), err))
} else {
p2p.Logger.Infof("Connected to: %s\n", peer)
}
}(p2p.ctx)
wg.Wait()
}
```
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: d02a55dbf926f9f1c6f3a57ac7682707fe3c2ff9
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.