I am using HTTPClient with WinHttpHanlder (for http/2) and my Polly retry policy looks something like this
var waitAndRetry = Policy
.HandleResult<HttpResponseMessage>(r => HTTPCodesWorthRetrying(r))
.Or<HandleRequestException>()
.Or<TimeoutRejectionException>().
WaitAndRetryAsync(
3,
retryAttempt => ExponentialBackoff(retryAttempt),
onRetry => {
//some logging
}
)
I have noticed that in case of HandleRequestException (with IOException or WinHttpException as inner exceptions) call is retried 3 times but still fails.
My question is :
Does Polly reconnects and establishes new connection during retry on errors like "connection was terminated abnormally" or "A connection with server could not be established" etc or "Server returned invalid or unrecognized response".
Or I am retrying too quickly, initial retry delay is 100ms ?
Did not find any details in polly documentation.
Polly's retry policy (or strategy in case of V8) is domain agnostic. That means they don't have any "smart" logic depending on what they are decorating. The exact same retry logic is executed for a mathematical calculation or for a network call.
For each and every attempt (including the initial attempt as well) the exact same user provided delegate/callback is executed. You have the ability to slightly modify the execution by changing a variable inside the
onRetrywhich is defined outside of the policy.Most probably yes. If there is a connection issue due to some transient network failure it is unlikely that it will self-heal via that short time. It is a good practice to use exponential back-off. This contrib defines a backoff strategy called
DecorrelatedJitterBackoffV2which can be really handy in this situation.