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

Protect against retry delay overflows #1522

Merged
merged 1 commit into from
Aug 30, 2023
Merged

Conversation

martintmk
Copy link
Contributor

@martintmk martintmk commented Aug 29, 2023

Details on the issue fix or feature implementation

If the calculated delay overflows just return TimeSpan.MaxValue.

Confirm the following

  • I started this PR by branching from the head of the default branch
  • I have targeted the PR to merge into the default branch
  • I have included unit tests for the issue/feature
  • I have successfully run a local build

@martintmk martintmk added the v8 Issues related to the new version 8 of the Polly library. label Aug 29, 2023
@martintmk martintmk added this to the v8.0.0 milestone Aug 29, 2023
@codecov
Copy link

codecov bot commented Aug 29, 2023

Codecov Report

Merging #1522 (eed38eb) into main (daf1529) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #1522   +/-   ##
=======================================
  Coverage   84.11%   84.12%           
=======================================
  Files         278      278           
  Lines        6586     6590    +4     
  Branches     1026     1026           
=======================================
+ Hits         5540     5544    +4     
  Misses        837      837           
  Partials      209      209           
Flag Coverage Δ
linux 84.12% <100.00%> (+<0.01%) ⬆️
macos 84.12% <100.00%> (+<0.01%) ⬆️
windows 84.12% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
src/Polly.Core/Retry/RetryHelper.cs 100.00% <100.00%> (ø)

Comment on lines +17 to +20
catch (OverflowException)
{
return TimeSpan.MaxValue;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering what's the use case for trapping the overflow, rather than throwing an exception and the user fixing their code/configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, maybe this really should be handled outside of Polly?

For example similar to how done here:

https://github.com/dotnet/extensions/blob/f1175430d64364b2a90e0188ba5caa8042c339f3/src/Libraries/Microsoft.Extensions.Http.Resilience/Internal/ValidationHelper.cs#L49

One use-case is really high number of retries, at some point the retry strategy will will fail with overflow.
Is it an user-error or Polly error?

Copy link
Contributor

@peter-csala peter-csala Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@martintmk
A kinda weird use case just bumped into my mind. (It is slightly related to this overflow problem) On StackOverflow once I have seen a question where the OP wanted to use the retry policy to schedule jobs to run them periodically (say once in a day).

I highly discouraged the OP to use Polly V7 for that. But what's the case for V8? Is the new implementation suitable for this use case? Or should be people directed to dedicated job scheduler solution?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not seems to be the use-case of Polly. Yes, you can misuse retries to do "periodical" executions, but eyebrows would be raised :)

Copy link
Contributor

@peter-csala peter-csala Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think would it make sense to have an "anti-patterns" section on the wiki/readme?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are enough of those, I would say yes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd agree - using Polly to do that sounds like a case of "when you have a hammer, everything looks like a nail".

We could maybe document anti-patterns, but I would only do so for things that are common mistakes or there's subtlety as to why they are - otherwise the number of things you shouldn't use Polly for is basically infinite.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will collect anti-patterns that I have seen on SO in the past 3 years and I'll create an issue to discuss them and come up with suggested alternatives for V8

@martintmk
Copy link
Contributor Author

@martincostello Is it ok to merge this one or should I abandon it?

My thinking is that even when user sets some crazy configuration, Polly should be able to handle it (by limiting the maximum delay to max, for example).

#1522 (comment)

@martincostello martincostello merged commit 3dd6a7a into main Aug 30, 2023
16 checks passed
@martincostello martincostello deleted the mtomka/timespan-overflow branch August 30, 2023 07:39
@martintmk martintmk mentioned this pull request Aug 30, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v8 Issues related to the new version 8 of the Polly library.
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants