Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Polly doesn't seem to be retrying on timeout errors #34

Open
TPitman-mindfiretechnology opened this issue Mar 10, 2023 · 0 comments
Open

Comments

@TPitman-mindfiretechnology

I am using the Microsoft.Extensions.Http.Polly in a Blazor app with Microservices all being hosted on Azure in docker.

I added a very simple use of Polly in my Program.cs like this:

static IAsyncPolicy<HttpResponseMessage> GetRetryPolicy()
{
return HttpPolicyExtensions
.HandleTransientHttpError()
.WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(4, retryAttempt)));
}

When I created my refit interfaces they use that policy like this:

builder.Services.AddRefitClient<IGeneralLedgerClient>()
.ConfigureHttpClient(config =>
{
config.BaseAddress = new Uri(baseUris!.AccountingApi!);
config.Timeout = TimeSpan.FromSeconds(15);
})
.AddPolicyHandler(GetRetryPolicy());

The containers on Azure are set to shut down after about 5 minutes. There is a Blazor website that calls the micro services. If you start the website after everything has shut down, the calls from the website to the micro services times out. If I open the Chrome or Edge dev tools and watch the network traffic I can see all the micro service calls time out after about 10 seconds.

If I simply hit refresh everything works because the micro services have all been started up from the call just a few seconds before.

This is why I added the above Polly code.

As far as I can tell Polly is not retrying.

You may notice that the retry fallback time starts at 4 so that the retries will happen at 1, 4 and 16 seconds just to give the micro services time to start up since it seems they need at least 10 seconds.

Why does this not seem to be retrying?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant