|
34 | 34 | let mut backoff = self.base_delay; |
35 | 35 | let mut retries = self.retries; |
36 | 36 |
|
37 | | - // SAFE: Substraction is only performed when retries > 0 |
| 37 | + // SAFE: Subtraction is only performed when retries > 0 |
38 | 38 | #[allow(clippy::arithmetic_side_effects)] |
39 | 39 | while backoff < self.max_delay && retries > 0 { |
40 | 40 | backoff = backoff.mul_f64(self.multiplier); |
@@ -173,12 +173,15 @@ impl<R> ExponentialBackoffBuilder<R> { |
173 | 173 | if self.jitter > 100.0 { |
174 | 174 | return Err(InvalidBackoff("jitter must not be greater than 100")); |
175 | 175 | } |
176 | | - if !self.jitter.is_finite() { |
| 176 | + if self.jitter.is_infinite() || self.jitter.is_nan() { |
177 | 177 | return Err(InvalidBackoff("jitter must be finite")); |
178 | 178 | } |
179 | 179 | if self.multiplier < 0.0 { |
180 | 180 | return Err(InvalidBackoff("multiplier must not be negative")); |
181 | 181 | } |
| 182 | + if self.multiplier.is_infinite() || self.multiplier.is_nan() { |
| 183 | + return Err(InvalidBackoff("multiplier must be finite")); |
| 184 | + } |
182 | 185 |
|
183 | 186 | Ok(ExponentialBackoff { |
184 | 187 | base_delay: self.base_delay, |
@@ -323,15 +326,15 @@ mod tests { |
323 | 326 | instance.tried(); |
324 | 327 | assert_eq!(total_time, Duration::from_secs(7)); |
325 | 328 |
|
326 | | - // third backoff |
| 329 | + // fourth backoff |
327 | 330 | total_time += instance.backoff(); |
328 | 331 | instance.tried(); |
329 | 332 | assert_eq!(total_time, Duration::from_secs(15)); |
330 | 333 |
|
331 | 334 | // reset |
332 | 335 | instance.reset(); |
333 | 336 |
|
334 | | - // fourth backoff |
| 337 | + // fifth backoff |
335 | 338 | total_time += instance.backoff(); |
336 | 339 | instance.tried(); |
337 | 340 | assert_eq!(total_time, Duration::from_secs(16)); |
|
0 commit comments