Retries
Requests retries on error statuses
Last updated
Requests retries on error statuses
Last updated
Gosip HTTP client is preconfigured with retry policies so different kinds of failures can be back off. Current implementation of policies assumes a specific number of retries for a specific response HTTP Status Code. One would only consider retries for "non-ok" status codes and only those which represents server or networking error which has chances for backing off on a next try.
The default policies are:
Retries' delay increases with each attempt: 200ms, 400ms, 800ms, 1.6s, 3.2s, and so on using the following progression formula:
For the responses with Retry-After
header, retry after value is used in preference as threshold is usually require longer wait until next request permitted.
A custom policy can be provided on demand in the following way:
When a specific request assumes no retries, e.g. resolving a folder which potentially doesn't exist but you know that 500 is returned in case of failure and it's a faster algorithm to try optimistically and check or create on an error only, it can be handy disabling any retries but only scoped to a specific request or series of requests.
For that purposes X-Gosip-NoRetry
header is the resolution.
There is no direct way to redefine delays between retries, there was no such demand. However, extending delays is achievable via OnRetry hook. The OnRetry
hook is called after it's known that a retry is needed but before the actual retry. The mechanics of retry checks is implemented in the way that should retry check
actually also waits for the delay. In other words, OnRetry
hook is fired right before the next retry is sent. So, if that hook is locked for a time the delay is increased correspondingly. That might be helpful for adding extra delay, yet won't work for the cases when the delays should be reduced or flatten.
While adding timeouts in hooks, make sure you're using something respecting context cancelation:
StatusCode
Retries
Description
401
5
Unauthorized. A retry might help if apply authentication restores an overdue token or handshake.
429
5
Too many requests throttling error response. In the case of API throttling (relevant for SharePoint Online), retrying is also aware of Retry-After header for delay detection.
500
1
Internal Server Error. Rarely can be restored.
503
10
Service Unavailable. Fixes intermittent issues with the service.
504
5
Gateway Timeout Error.