backoffDelay returns the minimum time the caller must wait before the (consecutiveFailures+1)-th attempt is allowed: 0, 1, 2, 4, 8, 16, 32, then capped at 60s.
(consecutiveFailures int)
| 186 | // (consecutiveFailures+1)-th attempt is allowed: 0, 1, 2, 4, 8, 16, 32, |
| 187 | // then capped at 60s. |
| 188 | func backoffDelay(consecutiveFailures int) time.Duration { |
| 189 | if consecutiveFailures < 1 { |
| 190 | return 0 |
| 191 | } |
| 192 | n := consecutiveFailures - 1 |
| 193 | if n > 6 { |
| 194 | n = 6 |
| 195 | } |
| 196 | d := time.Duration(1<<n) * time.Second |
| 197 | if d > 60*time.Second { |
| 198 | d = 60 * time.Second |
| 199 | } |
| 200 | return d |
| 201 | } |
| 202 | |
| 203 | func (l *attemptLimiter) reset(key string) { |
| 204 | l.mu.Lock() |
no outgoing calls