Skip to content

Commit

Permalink
Account for the first attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa committed Nov 19, 2023
1 parent 44a1e50 commit 48ed58c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions network/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ func (r *Retry) DialTimeout(network, address string, timeout time.Duration) (net
return net.DialTimeout(network, address, timeout) //nolint: wrapcheck
}

for ; retry < r.Retries; retry++ {
// The first attempt counts as a retry.
for ; retry <= r.Retries; retry++ {
// Wait for the backoff duration before retrying. The backoff duration is
// calculated by multiplying the backoff duration by the backoff multiplier
// raised to the power of the number of retries. For example, if the backoff
Expand All @@ -66,7 +67,7 @@ func (r *Retry) DialTimeout(network, address string, timeout time.Duration) (net
// 1 second * 2 ^ 9 = 1 minute (capped)
// 1 second * 2 ^ 10 = 1 minute (capped)
backoffDuration := r.Backoff * time.Duration(
math.Pow(r.BackoffMultiplier, float64(retry+1)),
math.Pow(r.BackoffMultiplier, float64(retry)),
)

if !r.DisableBackoffCaps && backoffDuration > BackoffDurationCap {
Expand Down

0 comments on commit 48ed58c

Please sign in to comment.