Skip to content

Commit

Permalink
backoff starts at 1 instead of zero (#62)
Browse files Browse the repository at this point in the history
NewTicker(time.Duration(0)) is illegal - let's prevent it from being able to
happen.
  • Loading branch information
jeanbza committed Nov 13, 2018
1 parent 9c40fc3 commit b001040
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions v2/call_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ func (bo *Backoff) Pause() time.Duration {
if bo.Multiplier < 1 {
bo.Multiplier = 2
}
// Select a duration between zero and the current max. It might seem counterintuitive to
// have so much jitter, but https://www.awsarchitectureblog.com/2015/03/backoff.html
// argues that that is the best strategy.
d := time.Duration(rand.Int63n(int64(bo.cur)))
// Select a duration between 1ns and the current max. It might seem
// counterintuitive to have so much jitter, but
// https://www.awsarchitectureblog.com/2015/03/backoff.html argues that
// that is the best strategy.
d := time.Duration(1 + rand.Int63n(int64(bo.cur)))
bo.cur = time.Duration(float64(bo.cur) * bo.Multiplier)
if bo.cur > bo.Max {
bo.cur = bo.Max
Expand Down

0 comments on commit b001040

Please sign in to comment.