in src/Microsoft.Extensions.Configuration.AzureAppConfiguration/Extensions/TimeSpanExtensions.cs [74:107]
public static TimeSpan CalculateBackoffDuration(this TimeSpan minDuration, TimeSpan maxDuration, int attempts)
{
if (minDuration <= TimeSpan.Zero)
{
throw new ArgumentOutOfRangeException(nameof(minDuration), minDuration, "The minimum backoff time should not be equal to or less than 0.");
}
if (maxDuration < minDuration)
{
throw new ArgumentOutOfRangeException(nameof(maxDuration), maxDuration, "The maximum backoff time should not be less than the minimum backoff time.");
}
if (attempts < 1)
{
throw new ArgumentOutOfRangeException(nameof(attempts), attempts, "The number of attempts should not be less than 1.");
}
if (attempts == 1)
{
return minDuration;
}
//
// IMPORTANT: This can overflow
double calculatedMilliseconds = Math.Max(1, minDuration.TotalMilliseconds) * (1L << Math.Min(attempts - 1, SafeShiftLimit));
if (calculatedMilliseconds > maxDuration.TotalMilliseconds ||
calculatedMilliseconds <= 0 /*overflow*/)
{
calculatedMilliseconds = maxDuration.TotalMilliseconds;
}
return TimeSpan.FromMilliseconds(calculatedMilliseconds).Jitter(JitterRatio);
}