Skip to content

Commit

Permalink
don't allow jitter to create a negative backoff, avoids panic
Browse files Browse the repository at this point in the history
  • Loading branch information
jrick committed Jan 27, 2025
1 parent 4803538 commit b597226
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion spv/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,11 @@ func (s *Syncer) connectToPersistent(ctx context.Context, raddr string) error {
// Persistent peers use a backoff duration scaled to 1/5th of
// discovered candidate peers (min 5s -> 1s, max 1m30s -> 18s).
jitter := backoffJitter()
connected := s.connectAndRunPeer(ctx, d/5+jitter, raddr, true)
scaledBackoff := d / 5
if scaledBackoff != 0 {
scaledBackoff += jitter
}
connected := s.connectAndRunPeer(ctx, scaledBackoff, raddr, true)
if err := ctx.Err(); err != nil {
return err
}
Expand Down

0 comments on commit b597226

Please sign in to comment.