Skip to content

Commit

Permalink
use exponential backoff, with jitter
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Apr 5, 2022
1 parent 220166c commit 1b1eeb0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion p2p/host/autorelay/relay_finder.go
Expand Up @@ -383,9 +383,12 @@ func (rf *relayFinder) moveCandidateToBackoff(cand *candidate) {
return
}
log.Debugw("moving candidate to backoff", "id", cand.ai.ID)
backoff := rf.conf.backoff * (1 << (cand.numAttempts - 1))
// introduce a bit of jitter
backoff = backoff * (16 + rand.Intn(8)) / 20
rf.candidatesOnBackoff = append(rf.candidatesOnBackoff, &candidateOnBackoff{
candidate: *cand,
nextConnAttempt: time.Now().Add(rf.conf.backoff),
nextConnAttempt: time.Now().Add(backoff),
})
}

Expand Down

0 comments on commit 1b1eeb0

Please sign in to comment.