522 questions
1
vote
1
answer
319
views
What Happens When HttpClient.PostAsync is Not Awaited
I'm inspecting some code that seems to throw
System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at times.
We use the library Polly for auto retries for ...
-1
votes
1
answer
521
views
ServerCertificateCustomValidationCallback is not invoked when using Polly
I'm using Polly to send https requests to an external server, the problem is the ServerCertificateCustomValidationCallback is never invoked:
public class CustomeHttpClient : HttpClientHandler {
...
....
2
votes
1
answer
1k
views
Polly Timeout optimistic using HttpClientFactory. How can I use cancellation token?
I would like to understand how to implement an optimistic timeout policy with Polly by using the HttpClientFactory.
In the examples on the net, the timeout policy is used when calling asynchronous ...
-1
votes
1
answer
2k
views
Retry with Polly ending in System.InvalidOperation The request message was already sent, cannot send the same request message multiple times
I'm sending data to a databricks api with a bad bearer token to test a Polly retry policy, but I get this exception:
InvalidOperation exception: The request message was already sent. Cannot send the ...
3
votes
1
answer
2k
views
Stop Execution on certain condition on Polly 4.3
We started using the Polly library in our legacy WinForms project which still runs on the .NET 4.0 framework (is a requisite).
The problem is that we have to use version 4.3 of the Polly library and ...
3
votes
1
answer
693
views
How do you pass a logger using HttpClientFactory and a PolicyRegistry?
I've been reading this which seems to have a way of doing what I want.
I've got something similar obviously, but within the PolicyContextExtensions the context.TryGetValue takes PolicyContextItems. ...
4
votes
1
answer
7k
views
How to Mock HTTPClient from IHttpClientFactory combined with Polly policies in .NET Core using Moq
I create a HTTP Client using IHttpClientFactory and attach a Polly policy (requires Microsoft.Extensions.Http.Polly) as follows:
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions....
5
votes
1
answer
8k
views
Polly HandleTransientHttpError not catching HttpRequestException
I've created a retry policy on my HttpClient in the Startup.ConfigureServices method. Note also that by default, asp.net core 2.1 logs 4 [Information] lines for each call made by the HttpClient which ...
1
vote
0
answers
648
views
HttpClient usage in polly
Wanted to verify if HttpCLient instance should be created outside method passed to polly for ExecuteAsync, or in?
My current usage varies between the two options and I am not sure which is the correct ...
4
votes
1
answer
2k
views
Polly CircuitBreaker - Dynamic Duration of Break
What's the correct way to modify the Duration Break on Polly?
I know in the documentation they mention implementing (PolicyRegistry).
Is there any example of this?
I was implementing Polly ...
1
vote
2
answers
3k
views
Polly and Multiple HttpClients
I want to use Polly in conjunction with my HttpClientFactory (in my C# .NET 5.0 project).
But the problem I have is that I have multiple named HttpClients in my factory and what I am trying to achieve ...
1
vote
1
answer
2k
views
HttpClient retry logic not working as expected (.Net Core 3.1)
In my Startup.cs I have the following lines of code:
services.AddHttpClient<CustomClientFactory>()
.AddTransientHttpErrorPolicy(
p => p.WaitAndRetryAsync(3,
...
3
votes
1
answer
4k
views
How do I add a Polly policy to a Refit Client created with a factory?
I have a refit client (IMyRefitClient) that returns
Task<ApiResponse<ADomainModel>>
I can't inject this refit client in Program.cs with HostBuilder.ConfigureServices because the url isn't ...
1
vote
1
answer
961
views
C# Retry two queries with Polly Retry
So I have 2 queries:
var a = await _aQuery.Execute(aId);
var b = await _bQuery.Execute(bId);
How can I retry execution of these queries with Polly Retry so that if any of them succeeds to get a non-...
3
votes
1
answer
4k
views
Polly retry request with different request-body
I have never used Polly before and am not sure if this is a good scenario for Polly.
I am calling an endpoint with a list of 1000 DTO in the POST body. Now the endpoint will perform some validations ...
3
votes
0
answers
2k
views
How to define a retry policy for transient errors when publishing messages to RabbitMQ?
I'm using the RabbitMQ.Client nuget package to publish messages to rabbitmq from a .NET core 3.1 application. We are using the 5.1.0 version of the library.
We want to improve the resiliency of our ...
-1
votes
1
answer
1k
views
how to re-try request for 401 along with TransientHttpError ( 5XX and 408)
Below code re-try 2 times when we have error from HttpRequestException, 5XX and 408 and it's works fine.
Here I want to re-try for even 401 error? how we can achieve this with Polly?
services....
1
vote
0
answers
1k
views
How to implement a kafka retry policy with publishing failed messages to a Dead Letter Topic in .NET?
I am searching on the internet to find a code example in .NET for implementing a kafka retry policy with publishing failed messages to a Dead Letter Topic (DLT/DLQ), but I can't find an example. Does ...
2
votes
1
answer
3k
views
Polly does not timeout
I am trying to get Polly to try again on timeout after 3 seconds and also when certain http codes are returned. However, it doesn't time out until after 100 seconds when the HttpClient times out.
Here ...
2
votes
1
answer
4k
views
How to include a return statement when executing a Polly policy?
Below is my code in C# Windows application, where connection with Oracle, FTP and Null Reference Exception are handled:
public Result Execute()
{
Result result = null;
string errorMessage = ...
1
vote
1
answer
2k
views
Best approach to load Azure Secrets in a .NET application
I'm trying to find the best solution to reload Azure Secrets in a .NET 5 application. I will write here what I have now.
First I did this:
.ConfigureAppConfiguration((context, configuration) =>
{
...
2
votes
0
answers
330
views
Polly .Net shut down application gracefully with IHostApplicationLifetime
The end outcome is to shut down the application if a specific type of exception (DatabaseException) has occurred.
However the current method HandleDatabaseException does not stop the application, the ...
4
votes
1
answer
2k
views
HttpClient TimeOut and Polly Bulkhead Policy problem
I'm having many timeouts exceptions using Polly Bulkhead policy, this policy helps me to limit the number of concurrent calls that I'm sending to a specific hosts. However It seems that the HttpClient ...
2
votes
1
answer
5k
views
How to log something before retry using Polly?
I'm attempting to log something before retrying a web api call using Polly in a .net core web api.
I know the web api is failing and returning a 503 response code however there's nothing in my console ...
1
vote
1
answer
726
views
Circuit breaker based on the condition in request
I need to set up the circuit break policy so that it would break the circuit only for some specific requests.
I have a sort of a gateway A calling API B which in turn calls C or D. I'm setting up a ...