Skip to content

Confusing enableSemaphoreDefaultBulkhead property #224

@OathMeadow

Description

@OathMeadow

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions