chitralverma commented on code in PR #7879:
URL: https://github.com/apache/opendal/pull/7879#discussion_r3536413813
##########
bindings/python/src/layers/retry.rs:
##########
@@ -82,15 +90,30 @@ impl RetryLayer {
retry = retry.with_max_times(max_times);
}
if let Some(factor) = factor {
+ if !factor.is_finite() || factor < 1.0 {
+ return Err(ConfigInvalid::new_err(
+ "factor must be a finite value greater than or equal to
1.0",
+ ));
+ }
retry = retry.with_factor(factor);
}
if jitter {
retry = retry.with_jitter();
}
if let Some(max_delay) = max_delay {
+ if !max_delay.is_finite() || max_delay < 0.0 {
+ return Err(ConfigInvalid::new_err(
+ "max_delay must be a finite, non-negative number of
seconds",
+ ));
+ }
retry = retry.with_max_delay(Duration::from_micros((max_delay *
1_000_000.0) as u64));
}
if let Some(min_delay) = min_delay {
+ if !min_delay.is_finite() || min_delay < 0.0 {
+ return Err(ConfigInvalid::new_err(
+ "min_delay must be a finite, non-negative number of
seconds",
+ ));
+ }
retry = retry.with_min_delay(Duration::from_micros((min_delay *
1_000_000.0) as u64));
}
Review Comment:
Adopted `Duration::try_from_secs_f64` for both `max_delay` and `min_delay`.
It preserves sub-microsecond precision and returns an error on
negative/NaN/inf/overflow, which is mapped to `ConfigInvalid`. This also
removes the now-redundant manual finite/non-negative guard and the `as u64`
cast. Added test cases for the overflow rejection.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]