I've got a C# API that communications with a web service that throws exceptions if it's too busy. I want to limit the number of parallel calls to this WCF service.
As the web service quickly throws exceptions when it's too busy, I want to use a Bulkhead in combination with a retry, and I explicitly want to have the Bulkhead to apply first to limit the number of calls waiting in the Retry Policy. The documentation of PolicyWrap says it usually should be the other way around, but in my case I need it like this.
However, it is not working. I'm running a performance test with 40 concurrent calls, and it keeps retrying all 40 calls in parallel.
This is the policy definition:
var retryPolicy = Policy.HandleResult<wcfResponse>(r => !r.IsSuccessStatus())
.Or<TimeoutException>()
.Or<CommunicationException>()
.WaitAndRetryAsync(60, i => TimeSpan.FromSeconds(1),
// setting maxParallel to 1 and a large queue,
// so I only expect one call to be retrying at the same time.
// However, it is doing all 40 calls in parallel,
// the bulkhead seems to be ignored and the retry policy
// kicks in for all requests in parallel.
var bulkHeadPolicy = Policy.BulkheadAsync(1, 100);
return bulkHeadPolicy.WrapAsync(retryPolicy);
What am I missing here?