By default RestClient doesn’t retry transient errors, however it is recomended that you configure the RetryHandler in your pipeline to retry transient errors.
The RetryHandler will retry a request if a transient fault occurs this could be DNS / host timeout etc or any status code > 500 e.g. Internal Server Error or Gateway Timeout. Both exponential and linear retry strategies are supported.
You configure the RetryHandler in your pipeline using the UseRetryHandler() extension method:
var config = new Config() .UseRetryHandler ( maxRetries:4, waitToRetryInSeconds:2, maxWaitToRetryInSeconds: 10, backOffStrategy: RetryHandler.BackOffStrategy.Exponential ); dynamic client = new RestClient("http://jsonplaceholder.typicode.com", config);
maxRetries How many times to retry the request if a transient fault occurs (this includes the first request).
waitToRetryInSeconds Sets the amount of seconds to wait between requests. If your backOffStrategy is linear the RetryHandler will just wait and retry after this time. If your backOffStrategy is Exponential then the RetryHandler will back off exponentially on each retry - in this example that would be 2, 4, 8… seconds.
maxWaitToRetryInSeconds The maximum amount of seconds to wait before retrying. In our example the 4th retry should wait for 16 seconds, however because maxWaitToRetryInSeconds is set to 10 it will wait 10 seconds.
backOffStrategy Can be
You can also use the UseRetryHandler() extension method with no parameters
var config = new Config().UseRetryHandler(); dynamic client = new RestClient("http://jsonplaceholder.typicode.com", config);
This sets a Exponential BackOffStrategy with maxRetries set to 3, waitToRetryInSeconds set to 1.44 and maxWaitToRetryInSeconds set to 10. This is optimum and safe for most use cases including Azure.