Questions tagged [polly]

Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner. Polly targets .NET Standard 1.1 and .NET Standard 2.0.

Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner. Polly targets .NET Standard 1.1 and 2.0+. For further information read Polly's wiki.

454 questions
21
votes
4 answers

Using Polly to retry after HttpStatusCode.Unauthorized

I'm making calls to an external API and want to deal with the event that a call returns an Unauthorized HttpResponseMessage. When this happens I want to refresh the access token and make the call again. I'm trying to use Polly with the following…
Vinyl Warmth
  • 2,226
  • 3
  • 25
  • 50
19
votes
1 answer

Using Polly for a retry attempt from an async function

I'm trying to retry a failed operation 3 times. I'm using Polly for a retry operation. I want to get the exception in case the retry operation fails and retry again 2 times and so on. return await Policy .Handle() …
Ace
  • 831
  • 2
  • 8
  • 28
16
votes
1 answer

What is the difference between AddTransientHttpErrorPolicy and AddPolicyHandler?

I want to apply resiliency strategy using Polly. I am using HttpClientFactory from ASP.NET Core 2.1. I found some guide on Polly GitHub wiki. There are two ways of such policy configuration - using AddTransientHttpErrorPolicy and AddPolicyHandler,…
16
votes
4 answers

Check string content of response before retrying with Polly

I'm working with a very flaky API. Sometimes I get 500 Server Error with Timeout, some other time I also get 500 Server Error because I gave it input that it can't handle SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999…
trailmax
  • 34,305
  • 22
  • 140
  • 234
14
votes
1 answer

Polly timeout policy clarification

I am trying to get the timeout policy to work correctly. I have the following requirements while integrating an api. Create an http request to invoke endpoint1 and pass the transactionID and capture the result if the http request does not receive…
Lorenzo
  • 29,081
  • 49
  • 125
  • 222
13
votes
1 answer

How can I get the retry count within a delegate executed through Polly retry policy?

I'm implementing Polly to retry requests in my C# web app. My sample code is included in this post. The code works as expected but the last parameter passed to CreateFile() (currently hard-coded as 0) needs to be the value of retryAttempt. How can…
user10816949
  • 131
  • 2
  • 7
13
votes
2 answers

Execute multiple policies

How to execute multiple policies (or combine them into a single one)? For example I have: var policy1 = Policy.Handle().WaitAndRetry(5)); var policy2 = Policy.Handle().RetryForever(); How to apply…
denny
  • 320
  • 3
  • 10
12
votes
3 answers

Refresh Token using Polly with Named Client

I have a policy that looks like this var retryPolicy = Policy .Handle() .OrResult(resp => resp.StatusCode == HttpStatusCode.Unauthorized) .WaitAndRetryAsync(3, retryAttempt =>…
user3236794
  • 578
  • 1
  • 6
  • 16
12
votes
3 answers

Polly policy to log exception and rethrow

I consider to use Polly to create policy to log exception and rethrow. I didn't find an existing method that allow it out of the box , but some options that I see are Fallback // Specify a substitute value or func, calling an action (e.g. for…
Michael Freidgeim
  • 26,542
  • 16
  • 152
  • 170
12
votes
1 answer

Polly Framework VS Microsoft Transient Fault Handling

I want to introduce transient fault handling in our .net application. I saw two nu-get packages are available as of now. One is Polly framework and the other one is Microsoft transient fault handling application block. We investigated and saw both…
Demon Hunter
  • 233
  • 1
  • 3
  • 15
11
votes
1 answer

What HTTP error codes are retried by Polly (.Net) by default?

I know I can specify the list of HTTP error codes (e.g. 408, 502, 503, etc. ) I would like to get retried using Polly, but what is the list of these codes that would be retried by default if none is specified?
Jose Parra
  • 877
  • 9
  • 23
11
votes
1 answer

Use a specific timeout connected to a retrypolicy

I'm creating a retry policy the following way: var policy = Policy.Handle().WaitAndRetryAsync... How to chail/build a timeout for the retrypolicy above? Policy.TimeoutAsync returns a TimeoutPolicy, hence I'm not able to do something…
Johan
  • 35,120
  • 54
  • 178
  • 293
10
votes
4 answers

Polly policy not working using "AddPolicyHandler"

I have an application that makes a request for an authenticated service, where it is necessary to pass the access_token. My idea is to use Polly to retry if the access_token is expired. I'm using Refit (v5.1.67) and Polly (v7.2.1) in a .NET Core 3.1…
Marcelo Diniz
  • 161
  • 1
  • 1
  • 8
10
votes
2 answers

Logging Polly wait and retry policy ASP.NET CORE 2.1

I need to log retry policy defined via Polly in APS.NET CORE 2.1+. My code is below showing Polly retry polly and using HttpClient. public IServiceProvider ConfigureServices(IServiceCollection services) { //... …
Pingpong
  • 7,681
  • 21
  • 83
  • 209
10
votes
1 answer

How to log retries from Polly with ILoggerFactory

Or: How to log from a static method. From https://github.com/App-vNext/Polly you have examples like this one where a logger is magically available: Policy .Timeout(30, onTimeout: (context, timespan, task) => { …
Terje
  • 357
  • 2
  • 14
1
2 3
30 31