Skip to content

Commit

Permalink
Fix retry overflow with max delay (#1868)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chr15P13t authored and martincostello committed Jan 4, 2024
1 parent 0348aae commit 149b6dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Polly.Core/Retry/RetryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public static TimeSpan GetRetryDelay(
}
catch (OverflowException)
{
if (maxDelay is { } value)
{
return value;
}

return TimeSpan.MaxValue;
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/Polly.Core.Tests/Retry/RetryHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ public void GetRetryDelay_Overflow_ReturnsMaxTimeSpan()
RetryHelper.GetRetryDelay(DelayBackoffType.Exponential, false, 1000, TimeSpan.FromDays(1), null, ref state, _randomizer).Should().Be(TimeSpan.MaxValue);
}

[Fact]
public void GetRetryDelay_OverflowWithMaxDelay_ReturnsMaxDelay()
{
double state = 0;

RetryHelper.GetRetryDelay(DelayBackoffType.Exponential, false, 1000, TimeSpan.FromDays(1), TimeSpan.FromDays(2), ref state, _randomizer).Should().Be(TimeSpan.FromDays(2));
}

[InlineData(1)]
[InlineData(2)]
[InlineData(3)]
Expand Down

0 comments on commit 149b6dd

Please sign in to comment.