Skip to content
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

Zero delay in ExponentialBackoff strategy after few retries #2

Open
PeterMaco opened this issue Sep 11, 2019 · 0 comments
Open

Zero delay in ExponentialBackoff strategy after few retries #2

PeterMaco opened this issue Sep 11, 2019 · 0 comments

Comments

@PeterMaco
Copy link

Setup ExponentialBackoff strategy with the following settings:
RetryCount = 100
MinBackoff = 1 second
MaxBackoff = 120 seconds
DeltaBackoff = 2 seconds

Use it in RetryPolicy and simulate retries (throw exception in ExecuteAsync).

Current Behaviour:
After 22 retries it starts to execute the action with delay 0.

Expected Behaviour
Action is executed with MaxBackoff delay (120 seconds).

Cause of the issue:
There is a bug in GetShouldRetry algorithm on this line:
int backoffMillisecond = (int)((Math.Pow(2.0, currentRetryCount) - 1.0) * random.Next((int)(this.deltaBackoff.TotalMilliseconds * 0.8), (int)(this.deltaBackoff.TotalMilliseconds * 1.2)));

There is a multiplication of 2 quite high integers and the result is greater than int.MaxValue. It results in overflow and negative result which is then set to 0 in RetryPolicy class:
if (zero.TotalMilliseconds < 0.0)
{
zero = TimeSpan.Zero;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant