diff --git a/src/Polly.Core/Retry/RetryHelper.cs b/src/Polly.Core/Retry/RetryHelper.cs index ec6dce016eb..35d3e5825eb 100644 --- a/src/Polly.Core/Retry/RetryHelper.cs +++ b/src/Polly.Core/Retry/RetryHelper.cs @@ -31,6 +31,11 @@ public static TimeSpan GetRetryDelay( } catch (OverflowException) { + if (maxDelay is { } value) + { + return value; + } + return TimeSpan.MaxValue; } } diff --git a/test/Polly.Core.Tests/Retry/RetryHelperTests.cs b/test/Polly.Core.Tests/Retry/RetryHelperTests.cs index 0deb85d2f7c..b5988eac425 100644 --- a/test/Polly.Core.Tests/Retry/RetryHelperTests.cs +++ b/test/Polly.Core.Tests/Retry/RetryHelperTests.cs @@ -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)]