Cancel in Retry Action
See original GitHub issueIs there a way to cancel additional retries within the retry action (synchronous)?
For example:
var policy = Policy
.Handle<OfflineException>()
.Retry(3, (ex, retryAttempt, ctx) =>
{
var result = MessageBox.Show("Please retry once the application is back online or cancel this request", "Application Offline", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
if (result != DialogResult.Retry)
{
//ToDo: cancel further attempts. ctx.AbortRetries(); ??
}
});
When executing a cancellation token can be passed but one would not necessarily have access to the token source during the retry action.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top Results From Across the Web
spring - How can I cancel a retry?
Using Spring Retry, I have a retry going on in 1 thread. In some circumstances, I would like to be able to cancel...
Read more >Cancelling a Polly Retry policy - Chris Roberts
If we run the application now, start the policy, then click “Stop Policy on Next Retry” we'll notice that our label briefly changes...
Read more >Cancel, Retry and Timeouts: Keep Your Sanity ... - YouTube
Have you ever had to orchestrate multiple tasks (some of which are asynchronous) and compose them together? As soon as latency comes into ......
Read more >Retry pattern - Azure Architecture Center
Cancel. If the fault indicates that the failure isn't transient or is unlikely to be successful if repeated, the application should cancel the...
Read more >Retry, Timeout and Cancel with fetch() : r/Frontend
Any network hiccup would likely cause requests to fail no matter what since the retry logic is too eager - fetch is called...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @rodion-m for the comment.
A better solution here (which I missed pointing out originally) is that
onRetry
is not really the place to decide whether an action should be retried. Polly already offers a well-defined, strongly-expressive API for whether exceptions should be retried: the.Handle<>()
clauses.So @Discofunk 's original problem could also be solved by:
Thanks @rodion-m for the suggestion that
sleepDurationProvider
could returnnull
to indicate “don’t retry”. Broadly, I am not in favour of having two places in an API to accomplish the same thing, as this tends to dilute the focus of the API overall (users will ask: “What is the difference?”). So, because Polly already has the strong API of the.Handle<>()
clauses to indicate whether to retry exceptions, we will probably not modifysleepDurationProvider
to also indicate this.Hello guys! @reisenberger, sorry, but your solution looks like a hack. Please consider a solution with a nullable
TimeSpan
in thesleepDurationProvider
and if it’snull
, it means just Cancel (without any unnecessary exceptions).