Reputation: 3567
I have a Blazor WebAssembly app using Entra auth, that calls a backend using the named HttpClient factory:
services.AddHttpClient(HttpClientProvider.WebAPI,
client => client.BaseAddress = new Uri(baseAddress))
.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>()
.AddStandardResilienceHandler(o => {
o.AttemptTimeout.Timeout = TimeSpan.FromSeconds(30);
o.CircuitBreaker.SamplingDuration = TimeSpan.FromSeconds(100);
})
;
But I am getting the following warnings, and sometimes timeout errors even after I completely removed the AddStandardResilienceHandler
.
warn: Polly[3] Execution attempt. Source: '-standard//Standard-Retry', Operation Key: '', Result: 'The operation didn't complete within the allowed timeout of '00:00:10'.', Handled: 'True', Attempt: '2', Execution Time: 10069.4ms Polly.Timeout.TimeoutRejectedException: The operation didn't complete within the allowed timeout of '00:00:10'.
In between, there sits a Yarp instance, but that one has higher timeouts. The warnings/errors are from the client.
[Update]
I changed the code based on suggestions, no change in the outcome.
services.AddHttpClient(HttpClientProvider.WebAPI,
client => {
client.BaseAddress = new Uri(baseAddress);
client.Timeout = TimeSpan.FromSeconds(30);
})
.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>()
.AddStandardResilienceHandler(o => {
o.AttemptTimeout.Timeout = TimeSpan.FromSeconds(30);
o.CircuitBreaker.SamplingDuration = TimeSpan.FromSeconds(100);
})
;
[Update2]
That's weird: after retrieving the options with:
var serviceProvider = services.BuildServiceProvider();
var monitor = serviceProvider.GetRequiredService<IOptionsMonitor<HttpStandardResilienceOptions>>();
var options = monitor.Get($"{HttpClientProvider.WebAPI}-standard");
I get 30 seconds. However, the message I get starts with "-standard", which when retrieved, has 10s.
The interesting part is that I retrieve the client with httpClientFactory.CreateClient(WebAPI)
which shouldn't return the latter but the former. What am I missing?
[Update3]
This gave me some insights - it seems that simply because it's chained there, won't necessarily affect it as I expected: https://www.milanjovanovic.tech/blog/overriding-default-http-resilience-handlers-in-dotnet For now, I stay with simply overriding the defaults instead.
Upvotes: -1
Views: 44