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

[Bug]: Retry Startegy stops retrying unexpectedly #1866

Closed
Chr15P13t opened this issue Dec 22, 2023 · 0 comments
Closed

[Bug]: Retry Startegy stops retrying unexpectedly #1866

Chr15P13t opened this issue Dec 22, 2023 · 0 comments
Labels
Milestone

Comments

@Chr15P13t
Copy link
Contributor

Describe the bug

Using DelayBackoffType.Exponential retry startegy in combination with MaxDelay eventually leads to "infinite" wait.

Delay computing method ignores MaxDelay in case of OverflowException and that leads to wait TimeSpan.MaxValue instead of MaxDelay

Expected behavior

When retry delay computing leads to TimeSpan OverflowException and a MaxDelay is defined, MaxDelay should be used.

Actual behavior

When retry delay computing leads to TimeSpan OverflowException, the applied Delay is TimeSpan.MaxValue regardless a MaxDelay is defined or not.

Steps to reproduce

Consider following retry strategy setup

new RetryStrategyOptions<bool>()
{
    OnRetry = args =>
    {
        _logger.LogWarning("(Key: {OperationKey}) attempt {AttemptCount} failed after {AttemptDuration}ms, next attempt will take place in {RetryDelay}s",
            args.Context.OperationKey,
            args.AttemptNumber,
            args.Duration.TotalMilliseconds,
            args.RetryDelay.TotalSeconds);

        return new ValueTask();
    },
    Delay = TimeSpan.FromSeconds(2),
    BackoffType = DelayBackoffType.Exponential,
    MaxDelay = TimeSpan.FromMinutes(5),
    MaxRetryAttempts = int.MaxValue
};

Observation in logs

Executing a pipeline base on this startegy leads to inconsistent behavior after the attempt 39, as I've observed in my logs:

(Key: 159e42ca-e781-48a8-927d-418b4ce8a811) attempt 0 failed after 1061.6031ms, next attempt will take place in 2s
(Key: 159e42ca-e781-48a8-927d-418b4ce8a811) attempt 1 failed after 248.2402ms, next attempt will take place in 4s
...
(Key: 159e42ca-e781-48a8-927d-418b4ce8a811) attempt 7 failed after 320.1541ms, next attempt will take place in 256s
(Key: 159e42ca-e781-48a8-927d-418b4ce8a811) attempt 8 failed after 950.9286ms, next attempt will take place in 300s
...
(Key: 159e42ca-e781-48a8-927d-418b4ce8a811) attempt 38 failed after 294.6921ms, next attempt will take place in 300s
(Key: 159e42ca-e781-48a8-927d-418b4ce8a811) attempt 39 failed after 298.6555ms, next attempt will take place in 922337203685.4775s

Exception(s) (if any)

No response

Polly version

8.0.0

.NET Version

net7.0

Anything else?

Investigation

In https://github.com/App-vNext/Polly/blob/main/src/Polly.Core/Retry/RetryHelper.cs RetryHelper.GetRetryDelay() has been updated with Introduce RetryStrategyOptions.MaxDelay property #1620

But OverflowException handling introduced with commit 3dd6a7a has not been updated to take new MaxDelay property in account.

@Chr15P13t Chr15P13t added the bug label Dec 22, 2023
@martincostello martincostello added this to the v8.3.0 milestone Dec 26, 2023
@martincostello martincostello modified the milestones: v8.3.0, v8.2.1 Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants