I am not sure if this is a bug, but It feels like one.
Background
As we know, by default, if no Bulkhead is configured, then Spring Cloud Circuit Breaker will use the ThreadPoolBulkhead for each circuit breaker. For us, we prefer semaphores for our event driven services, we have no need for thread pools. So, we found the property spring.cloud.circuitbreaker.resilience4j.enableSemaphoreDefaultBulkhead and we set it to true.
Confusion
For a service where all HTTP clients use a semaphore bulkhead, except one. What happens if the above property is set to true and ThreadPoolBulkhead is configured for the HTTP client X? The answer is a semaphore bulkhead!
This is the confusion, a ThreadPoolBulkhead configuration will never bite when the enableSemaphoreDefaultBulkhead is set to true. This property should instead be named forceSemaphoreBulkhead.
The code seems incorrect in my opinion. This parameter should default to a semaphore bulkhead, if no configuration says otherwise. The code I am talking about resides in the class Resilience4jBulkheadProvider.
private boolean useSemaphoreBulkhead(String id) {
return semaphoreDefaultBulkhead
|| (bulkheadRegistry.find(id).isPresent() && threadPoolBulkheadRegistry.find(id).isEmpty());
}
So basically the semaphoreDefaultBulkhead, in my opinion, should be checked if no SemaphoreBulkhead or ThreadPoolBulkhead exists, then default to a SemaphoreBulkhead, else a ThreadPoolBulkhead.
Why even Mix?
Well, the ThreadPoolBulkhead is preferable for our non-event driven services. Semaphores cannot be queued, only timed. But this applies only for certain clients. As it is now, we need to turn this flag off, and we have to explicitly configure all clients.
Have we misunderstood this flag?
Thank you
I am not sure if this is a bug, but It feels like one.
Background
As we know, by default, if no Bulkhead is configured, then
Spring Cloud Circuit Breakerwill use theThreadPoolBulkheadfor each circuit breaker. For us, we prefer semaphores for our event driven services, we have no need for thread pools. So, we found the propertyspring.cloud.circuitbreaker.resilience4j.enableSemaphoreDefaultBulkheadand we set it totrue.Confusion
For a service where all HTTP clients use a semaphore bulkhead, except one. What happens if the above property is set to
trueandThreadPoolBulkheadis configured for the HTTP clientX? The answer is a semaphore bulkhead!This is the confusion, a
ThreadPoolBulkheadconfiguration will never bite when theenableSemaphoreDefaultBulkheadis set totrue. This property should instead be namedforceSemaphoreBulkhead.The code seems incorrect in my opinion. This parameter should
defaultto a semaphore bulkhead, if no configuration says otherwise. The code I am talking about resides in the classResilience4jBulkheadProvider.So basically the
semaphoreDefaultBulkhead, in my opinion, should be checked if noSemaphoreBulkheadorThreadPoolBulkheadexists, then default to aSemaphoreBulkhead, else aThreadPoolBulkhead.Why even Mix?
Well, the
ThreadPoolBulkheadis preferable for our non-event driven services. Semaphores cannot be queued, only timed. But this applies only for certain clients. As it is now, we need to turn this flag off, and we have to explicitly configure all clients.Have we misunderstood this flag?
Thank you