-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ExecuteSuspendFunction Fails as delayMs Unexpectedly Becomes Zero #2148
Comments
Hello, |
Hi,
I think there shouldn’t be any issues with backward compatibility, but what do you think? |
I think I would prefer that the random function can only return 1 ms as a minimum |
Nice. How about trying it this way?
|
Looks good to me |
I've created a PR, could you take a look? Also, should I include the following test code? public void shouldAcceptRandomizationFactorOfOne() {
final Duration duration = Duration.ofMillis(100);
final float largestFactor = 1.0f;
Try<IntervalFunction> attempt = Try.of(() -> IntervalFunction.ofRandomized(duration, oneFactor));
// Assert that the attempt is successful and does not result in an exception
assertThat(attempt.isSuccess()).isTrue();
assertThat(attempt.getCause()).isNull();
} |
Resilience4j version:1.17.0
Java version:17
Kotlin version: 1.6.10
I have configured
core.IntervalFunction.ofExponentialRandomBackoff
with an initial value of 1 and a multiplier of 2.0. Additionally, I designatedexecuteSuspendFunction
as a suspend function to handle retries upon failures. However, I've observed that sometimes retries fail and sometimes they succeed. This prompted me to examine the code further.Upon inspecting
executeSuspendFunction
, I noticed that when an exception occurs, ifdelayMs
is less than 1, the exception is rethrown. Internally, there are instances wheredelayMs
calculates to 0, which appears to be unintended behavior and thus seems to be a edge caseThe root cause of this issue lies in the implementation of the
randomize
function. Whencurrent
is 1, the resulting value can range from 0.5 to 1.5.If the return value is 0.5, the delay value generated by
ofExponentialRandomBackoff
might be cast to long as 0.This means that the variable
delayMs
withinexecuteSuspendFunction
becomes 0, causing an exception to be thrown and the process to terminate.Setting a retry interval to 0 is not in line with the intentions of this project. Notably, the code specifies that the initial interval setting should not be less than 1.
May I proceed with handling this edge case?
The text was updated successfully, but these errors were encountered: