use exponential backoff, with jitter

This commit is contained in:
Marten Seemann 2022-04-05 18:22:58 +01:00
parent 220166ce78
commit 44350ef427
1 changed files with 4 additions and 1 deletions

View File

@ -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 * time.Duration(16+rand.Intn(8))) / time.Duration(20)
rf.candidatesOnBackoff = append(rf.candidatesOnBackoff, &candidateOnBackoff{
candidate: *cand,
nextConnAttempt: time.Now().Add(rf.conf.backoff),
nextConnAttempt: time.Now().Add(backoff),
})
}