With #1757 , I wonder if it's safe to add Polly for transient error handling/retry like this:
services.AddHttpClient("allowsDecompression").ConfigurePrimaryHttpMessageHandler(...)
.AddTransientHttpErrorPolicy(policy => policy.WaitAndRetryAsync(new[]
{
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(2),
TimeSpan.FromSeconds(3)
}));
services.AddHttpClient("disallowsDecompression").ConfigurePrimaryHttpMessageHandler(...)
.AddTransientHttpErrorPolicy(policy => policy.WaitAndRetryAsync(new[]
{
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(2),
TimeSpan.FromSeconds(3)
}));
Or does the Google API SDK already implement some kind of retry handler?
There is already retry handling in ConfigurableMessageHandler, but it's fairly primitive.
I expect it would be okay to use Polly as well, but you'd probably want to be careful not to use both retry strategies at the same time (as otherwise you could end up with multiplicative effects, e.g. 6 retries instead of either 3 or 2 if both layers retried).
@amanda-tarafa does that sound about right to you?
There shouldn't be any problem with handling retry yourself, via Polly or any other mechanism. But I agree with @jskeet that you should deactivate our default retry strategy, else, we'll retry first, and they you'll get to retry, with the multiplicative effect that Jon mentioned. You can do that as follows (example with TranslateService, but the same applies for all other Google.Apis service clients)
new TranslateService(new BaseClientService.Initializer
{
....
DefaultExponentialBackOffPolicy = ExponentialBackOffPolicy.None
});
As extra info:
ExponentialBackOffPolicy.UnsuccessfulResponse503 which retries 3 times with backoff for 503 responses.ExponentialBackOffPolicy.Exception, then we would retry 3 times with backoff for any exception.ExponentialBackOffPolicy.UnsuccessfulResponse503 and ExponentialBackOffPolicy.Exception.@jskeet pointed out something from my reply, and it's that with the Polly configuration set on the HttpClient you'll get to retry first and then us, and not the other way around as I said.
@amanda-tarafa @jskeet Thank you for the detailed responses!