polynomialbackoff: added checks for small degree polynomials
@@ -103,7 +103,14 @@ type polynomialBackoff struct {
}
func (b *polynomialBackoff) Delay() time.Duration {
- polySum := b.poly[0]
+ var polySum float64
+ switch len(b.poly) {
+ case 0:
+ return 0
+ case 1:
+ polySum = b.poly[0]
+ default:
+ polySum = b.poly[0]
exp := 1
attempt := b.attempt
b.attempt++
@@ -112,6 +119,7 @@ func (b *polynomialBackoff) Delay() time.Duration {
exp *= attempt
polySum += float64(exp) * c
}
+ }
return b.jitter(time.Duration(float64(b.timeUnits)*polySum), b.min, b.max, b.rng)
}
