-
Notifications
You must be signed in to change notification settings - Fork 7
Description
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;
}