Skip to content

Commit

Permalink
time.Until the zero time is very wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
jrick committed Jan 28, 2025
1 parent 9438178 commit 1f22188
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion spv/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ var errBreaksMinVersionTarget = errors.New("peer uses too low version to satisif
// peer. It blocks until the peer disconnects and logs any errors.
func (s *Syncer) connectAndRunPeer(ctx context.Context, backoff time.Duration, raddr string, persistent bool) (connected bool) {
if backoff > 0 {
log.Tracef("connectAndRunPeer(%v): sleeping backoff %v", raddr, backoff)
select {
case <-time.After(backoff):
case <-ctx.Done():
Expand Down Expand Up @@ -702,7 +703,12 @@ func (s *Syncer) connectToCandidates(ctx context.Context) error {
raddr := na.String()
b := s.backoff(raddr)
jitter := backoffJitter()
delay := time.Until(b.time) + jitter
var delay time.Duration
if b.time.IsZero() {
delay = jitter
} else {
delay = time.Until(b.time) + jitter
}
connected := s.connectAndRunPeer(ctx, delay, raddr, false)
if connected {
s.setBackoff(raddr, backoff{})
Expand Down

0 comments on commit 1f22188

Please sign in to comment.