Quantcast
Channel: Active questions tagged retry-logic - Stack Overflow
Viewing all articles
Browse latest Browse all 950

How can I return 408 Request timeout to Polly so that it can apply retry policy?

$
0
0

I have the following client app

services    .AddHttpClient<IOrderService, OrderService>(c =>    {        c.BaseAddress = new Uri(Configuration["ApiSettings:xxx"]);    })    .AddPolicyHandler(GetRetryPolicy())private static IAsyncPolicy<HttpResponseMessage> GetRetryPolicy(){    return        HttpPolicyExtensions            .HandleTransientHttpError()            .WaitAndRetryAsync(                retryCount: 3,                sleepDurationProvider: currNthRetry => TimeSpan.FromSeconds(Math.Pow(2, currNthRetry)),                onRetry: (Exception, retryCount, context) =>                {                    // ...                });}

so when the server is down/off, my client app is just hung, polly doesn't apply retry policy, I think it is because Polly expects to receive http status code of 408 Request Timeout first, then it can retry, but the server is down, the server cannot generate 408 error code and sent it back to the for sure. so how can I set the default timeout for Polly?

I was trying to set timeout in HttpClient as:

services    .AddHttpClient<IOrderService, OrderService>(c =>    {        // ...        c.Timeout = TimeSpan.FromSeconds(5);    })    // ...

but it doesn't work, all I got is a TaskCanceledException as below picture shows:

enter image description here

and Polly still doesn't do any retry.

So how can I return a 408 status code for Polly to consume?


Viewing all articles
Browse latest Browse all 950

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>