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
10
votes
1 answer

Should Polly Policies be singletons?

I have a query, IGetHamburgers, that calls an external API. I've registered the implementation of IGetHamburgers in my DI container as a Singleton. Im using Polly as a Circuitbreaker, if two requests fails the circuit will open. My goal is that all…
JOSEFtw
  • 9,781
  • 9
  • 49
  • 67
9
votes
2 answers

Implementing retry logic with Polly library with no exception handling repeatedly

how to implement retry logic using polly to retry executing a function forever with some delay but handle no exception. the scenario is to get status information repeatedly but there is no expected exception.
TrustyCoder
  • 4,749
  • 10
  • 66
  • 119
9
votes
1 answer

Testing Polly retry policy with moq

I'm trying to write a unit test for polly, but it looks like the return is cached. Method PostAsyncWithRetry: using Polly; using System; using System.Diagnostics; using System.Net.Cache; using System.Net.Http; public class RetryClient { private…
Karis
  • 472
  • 2
  • 5
  • 16
8
votes
3 answers

How to mock a method with CancellationToken passed as parameter?

I'm recently learning and using Polly to add resilience to my code, especially for the timeout and retry policies. However, I don't know how to unit test the code with polly. To be more specific, I don't know how to mock a method with Cancellation…
Jane.L
  • 333
  • 1
  • 5
  • 13
8
votes
1 answer

Polly Retry All Exceptions Except Specific Condition

Is there a way in Polly to retry all exceptions apart from those which are specified.. for example: var p = Policy .Handle(e => !(e.NativeErrorCode == 1)) .Or() .RetryAsync(); Here i have picked a…
m1nkeh
  • 1,337
  • 23
  • 45
7
votes
1 answer

Understanding the semantics of Polly policies when separating policy definition from execution

With Polly I'd like to have my policy definition and the execution of that policy in two different statements, as in: // Policy definition var policy = Policy .HandleResult(predicate) .Retry(2); // Policy…
Howiecamp
  • 2,981
  • 6
  • 38
  • 59
7
votes
1 answer

Exception User-Unhandled reported in VS Debugger when using Polly

I'm using Polly to catch an exception while calling a Pittney Bowes Geocoder service. I'm using a g1client library that throws a MessageProcessingException. I've wrapped the call in a Polly network policy to retry the call up to 3 times if this…
user2197446
  • 1,065
  • 3
  • 15
  • 31
7
votes
1 answer

How to tell from Npgsql exception if the call is worth a retry (transient fault strategy)

I'm writing a service which will be connecting to a remote postgres server. I'm looking for a good way to determine which exceptions should be treated as transient (worth retrying), and how to define an appropriate policy for connecting to a remote…
Dominick O'Dierno
  • 145
  • 1
  • 2
  • 7
7
votes
3 answers

Polly's CircuitBreakerAsync does not retry if exception occur

I am using Polly library for transient fault handling. For synchronous operations Polly circuit breaker policy works fine but when I created its async version it does not retries the execution. Kindly suggest : Asynchronous method: private async…
Demon Hunter
  • 233
  • 1
  • 3
  • 15
6
votes
1 answer

Injected HttpClient ignores IHttpClientFactory configuration

I've created a custom library which automatically sets up Polly policies for specific services which depend on HttpClient. This is done using the IServiceCollection extension methods and the typed client approach. A simplified example: public static…
Flater
  • 12,908
  • 4
  • 39
  • 62
6
votes
1 answer

Configuring Polly library to fallback to cached values only if service is not available

I am very new to polly. I did a bit of research but still could not find out if/how it is possible to use Polly in an elegant way to use a chached value only if a request fails. Example: Service A wants to get data from a service B via http. I…
feffe
  • 73
  • 6
6
votes
2 answers

Send parallel requests but only one per host with HttpClient and Polly to gracefully handle 429 responses

Intro: I am building a single-node web crawler to simply validate URLs are 200 OK in a .NET Core console application. I have a collection of URLs at different hosts to which I am sending requests with HttpClient. I am fairly new to using Polly and…
Collin Barrett
  • 2,441
  • 5
  • 32
  • 53
6
votes
1 answer

How to use Named Arguments in F#

Calling a Dictionary's Add() method using named arguments works in F#. let d = Dictionary() d.Add(key = "five", value = 5) let d2= Dictionary() d2.Add(key = "five", value = 5) d2.Add(key = 5, value = 5) In Polly's Context…
Brett Rowberry
  • 1,030
  • 8
  • 21
6
votes
2 answers

Polly Retry policy with Function is not waiting for result

I am trying to convert my existing function to Polly Retry policy public static T Execute(Func getTask) where T : Task { var retryCount = 3; while (retryCount-- > 0) { try { getTask().Wait(); …
RaceBase
  • 18,428
  • 47
  • 141
  • 202
6
votes
3 answers

How to use Polly with Flurl.Http?

Currently I have this request: await url .SetQueryParams(queryString) .SetClaimsToken() .GetJsonAsync() I'd like to start using Polly (https://github.com/App-vNext/Polly) now to handle retries and provide a better user experience.…
eestein
  • 4,914
  • 8
  • 54
  • 93
1
2
3
30 31