I have a situation where I try to use a Retry Policy and a Timeout Policy that is applied to every http call when the first call fails.
I have some parameters that are read from configuration: retryCount
, sleep
and the timeout
value.
services.AddHttpClient<Authentication>()
.AddPolicyHandler((services, request) => HttpPolicyExtensions.HandleTransientHttpError()
.OrResult(msg => msg.StatusCode == System.Net.HttpStatusCode.BadGateway)
.OrResult(msg => msg.StatusCode == System.Net.HttpStatusCode.RequestTimeout)
.Or<TimeoutRejectedException>()
.WaitAndRetryAsync(retryCount, retryAttempt => TimeSpan.FromSeconds(Math.Pow(sleep, retryAttempt))))
.AddPolicyHandler(HttpResponseMessageExtensions.GetTimeoutPolicy(DefaultTimeoutInMinutes));
Is there any preferred solution or any formula that can be used for the relationship between the timeout per retry, the timeout per client and/or the sleep value?
In my case the time taken for a failed call exceeds the timeout value when the retryCount
has a big value and I receive this error message:
As far as I know the timeout per client is by default 100s and can be changed but what is the better option for choosing the values?
I also read something about a backoff mechanism but I am not sure how it works.