github-vet / github-vet/rangeloop-pointer-findings
SummerCash/go-summercash: p2p/p2p_host.go; 41 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [SummerCash/go-summercash](https://www.github.com/SummerCash/go-summercash) at [p2p/p2p_host.go](https://github.com/SummerCash/go-summercash/blob/cf6e68db2069ad747ae74a8340dba732bc5d5eda/p2p/p2p_host.go#L92-L132)
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 106
[Click here to see the code in its original context.](https://github.com/SummerCash/go-summercash/blob/cf6e68db2069ad747ae74a8340dba732bc5d5eda/p2p/p2p_host.go#L92-L132)
Click here to show the 41 line(s) of Go which triggered the analyzer.
```go
for peer := range peerChan { // Iterate through discovered peers
if peer.ID == host.ID() || !CheckPeerCompatible(ctx, WorkingHost, peer.ID, network) { // Check is self
continue // Skip
}
common.Logf("== P2P == discovered peer: %s\n", peer.ID.String()) // Log discovered peer
startTime := time.Now() // Get start time
done := false // Init done buffer
var connectionErr error // Init error buffer
go func(done *bool) {
err = WorkingHost.Connect(ctx, peer) // Connect to discovered peer
if err != nil { // Check for errors
connectionErr = err // Write error
return // Continue to next peer
}
common.Logf("== P2P == connected to peer %s\n", peer.ID.String()) // Log connected peer
*done = true // Set done
}(&done) // Run
for !done { // Wait until done
if time.Now().Sub(startTime) > 10*time.Second { // Check for timeout
common.Logf("== P2P == peer %s timed out\n", peer) // Log timeout
break // Break
}
if connectionErr != nil { // Check for errors
common.Logf("== P2P == errored while connecting to peer %s: %s\n", peer, connectionErr.Error()) // Log error
break // Break
}
}
}
```
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: cf6e68db2069ad747ae74a8340dba732bc5d5eda
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.