Skip to content

Commit

Permalink
use Throw to bubble the error up
Browse files Browse the repository at this point in the history
Co-authored-by: Peter Argue <[email protected]>
  • Loading branch information
tarakby and peterargue authored Jun 13, 2023
1 parent 908212f commit 5a1bca3
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions network/p2p/connection/peerManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,10 @@ func (pm *PeerManager) updateLoop(ctx irrecoverable.SignalerContext) {
func (pm *PeerManager) periodicLoop(ctx irrecoverable.SignalerContext) {
// add a random delay to initial launch to avoid synchronizing this
// potentially expensive operation across the network
r, _ := rand.Uint64n(uint64(pm.peerUpdateInterval.Nanoseconds()))
// ignore the error here, if randomness fails `r` would be zero and there will be no delay
// for the current node
// TODO: treat the error properly instead of swallowing it. In this specific case, `utils/rand`
// only errors if there is a randomness system issue. Such issue will cause errors in many
// other components.
r, err := rand.Uint64n(uint64(pm.peerUpdateInterval.Nanoseconds()))
if err != nil {
ctx.Throw(fmt.Errorf("unable to generate random interval: %w", err))
}
delay := time.Duration(r)

ticker := time.NewTicker(pm.peerUpdateInterval)
Expand Down

0 comments on commit 5a1bca3

Please sign in to comment.