I'm having many timeouts exceptions using Polly Bulkhead policy, this policy helps me to limit the number of concurrent calls that I'm sending to a specific hosts. However It seems that the HttpClient Timeout time affects the whole delegates.
I'm using IHttpClientFactory to configure that with the following code:
services.AddHttpClient(string.Empty)
.AddPolicyHandler(GetBulkheadPolicy(100));
private static IAsyncPolicy<HttpResponseMessage> GetBulkheadPolicy(int maxConcurrentRequests)
{
return Policy.BulkheadAsync(maxConcurrentRequests, int.MaxValue)
.AsAsyncPolicy<HttpResponseMessage>();
}
My problem is that I want that the timeout only affects to the request itselft and no to the bulkhead policy, because that behaviour that I want to achieve is the following:
- Limit the number of concurrent requests to a specific host
- Wait infinitely until there is capacity to send the requests (when the queque will be full, Polly will raise an exception)
- Send the request to the host and apply a timeout, for example the default one.
I have achieve that behaviour using a Semaphore instead of a Bulkhead Polly Policy but I'd like to encapsulate that code using a Policy.
Thanks.