spring-cloud / spring-cloud-circuitbreaker

Spring Cloud Circuit Breaker API and Implementations
Apache License 2.0
329 stars 110 forks source link

BulkheadProvider - Backend service code getting executed even if maxConcurrentCalls limit is reached #102

Closed Shabin closed 1 year ago

Shabin commented 3 years ago

I was trying to setup a sample with resilience4j semaphore bulkhead support with maxConcurrentCalls set as 1.

resilience4j.bulkhead:
    instances:
        backendA:
            maxConcurrentCalls: 1

My backend service code:

public String test() {
 System.out.println("executing in thread : " + Thread.currentThread().getName());
 try {
  Thread.sleep(10000);
 } catch (InterruptedException e) {
  e.printStackTrace();
 }
 return "hello";
}

When one call was waiting on the backend service to get a response, I made a second call to the same service.

return cbf.create("backendA").run(() -> backService.test());

Even though the second call failed with Bulkhead 'backendA' is full and does not permit further calls exception, my backend service code was executed anyway and I got the logs.

executing in thread : ForkJoinPool.commonPool-worker-1
executing in thread : ForkJoinPool.commonPool-worker-2
exception io.github.resilience4j.bulkhead.BulkheadFullException: Bulkhead 'backendA' is full and does not permit further calls

On debugging Resilience4jBulkheadProvider, found that CompletableFuture<T> asyncCall = CompletableFuture.supplyAsync(supplier); started a forkjoinpool thread and backend code execution was initiated even before the semaphore check was done.

I was under the impression that the backend code will be called only if semaphore check was succeeded.

geowalrus4gh commented 3 years ago

we also have the same issue here. waiting for a response from the community.

spencergibb commented 3 years ago

What version are you using? Support for configuring by properties wasn't released in Hoxton.SR11 until April 21

Shabin commented 3 years ago

That time I checked out the master code and used it for verifying the functionality. Now I tried the same with the spring-cloud-starter-circuitbreaker-resilience4j 2.0.2 version and found the same issue.

ryanjbaxter commented 2 years ago

Can you provide a complete, minimal, verifiable sample that reproduces the problem? It should be available as a GitHub (or similar) project or attached to this issue as a zip file.

spring-cloud-issues commented 2 years ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-cloud-issues commented 2 years ago

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.