I use Polly to retry HTTP Requests. The following code works fine:
IAsyncPolicy<HttpResponseMessage> waitTimeout = Policy.TimeoutAsync<HttpResponseMessage>(TimeSpan.FromSeconds(5));// Retry policy for transient errorsIAsyncPolicy<HttpResponseMessage> retry = HttpPolicyExtensions.HandleTransientHttpError() .Or<TaskCanceledException>() .Or<TimeoutRejectedException>() .OrResult(msg => msg.StatusCode == System.Net.HttpStatusCode.ServiceUnavailable) .OrResult(msg => msg.StatusCode == System.Net.HttpStatusCode.InternalServerError) .WaitAndRetryAsync(12, _ => TimeSpan.FromSeconds(10));// Register the HTTP client with the Polly policiesbuilder.Services.AddHttpClient("ApiClient", client => {client.Timeout = TimeSpan.FromSeconds(230); }) .AddHeaderPropagation() .AddPolicyHandler(Policy.WrapAsync(retry, waitTimeout));
The time before the next retry is 10 seconds and the timeout for each request within the retry is 5 seconds.The problem is that the API service can respond slowly. I would like to have the exponential timeout for each request within retry (not delay time)