You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Resilience4J Bulkheads - Thread doesn't get interrupted with Timelimiter & BulkheadΒ #163
Describe the bug
When using a timelimiter + semaphore bulkhead, if the timelimiter's time is exceeded, the underlying thread executing is not interrupted but the bulkhead permit is released. This means if the restricted section inside the bulkhead is consistently timing out, more concurrent requests are submitted than what the bulkhead should allow.
This happens because the Resilience4JBulkheadProvider uses CompletableFuture.supplyAsync and Completable Futures can't be interrupted.
The sample repository contains two test classes that are almost identical: BulkheadDisabledTests and BulkheadEnabledTests. BulkheadDisabledTests passes but BulkheadEnabledTests fails because the thread is not interrupted.
Possible solution
Use Bulkhead.decorateSupplier instead of Bulkhead.decorateCompletionStage to create the bulkhead and then use an executor service with a normal future (possibly the same one that is already used in the Resilience4JCircuitBreaker ) for the time limiter.
Swap the order of the bulkhead and the timelimiter so the time limiter happens inside the bulkhead and can interrupt the task (This would also fix the thread pool bulkhead which works only with CompletionStage and has a similar problem)
I would be willing to submit a pull request for this
changed the title [-]Resilience4J Bulkheads - Thread doesn't get interrupted with Timelimiter & Semaphore bulkhead[/-][+]Resilience4J Bulkheads - Thread doesn't get interrupted with Timelimiter & Bulkhead[/+]on Feb 8, 2023
Not su if it is related but currently, the ThreadPoolBulkhead is not auto closing resources.
Tested by using Spring Cloud Circuit Breaker in a batch job, the batch hangs and never finishes as the bulkhead threads are not closed. When configure to use semaphore works fine.
Activity
[-]Resilience4J Bulkheads - Thread doesn't get interrupted with Timelimiter & Semaphore bulkhead[/-][+]Resilience4J Bulkheads - Thread doesn't get interrupted with Timelimiter & Bulkhead[/+]ryanjbaxter commentedon Feb 8, 2023
@Mistborn94 a PR would be quite welcome!
wllianwd commentedon Feb 20, 2023
Not su if it is related but currently, the ThreadPoolBulkhead is not auto closing resources.
Tested by using Spring Cloud Circuit Breaker in a batch job, the batch hangs and never finishes as the bulkhead threads are not closed. When configure to use semaphore works fine.
More info here:
resilience4j/resilience4j#1199
Mistborn94 commentedon Nov 27, 2023
Pull request has been up for a while now #164