Unexpected behavior when fallback methods are called
See original GitHub issueResilience4j version: 1.7.1 (resilience4j-spring-boot2)
Java version: 11 Spring Boot Version: 2.5.4
I tried combining @TimeLimiter
and @CircuitBreaker
with different fallback methods, like this:
@Bulkhead(name = "getSearchResult", type = Type.THREADPOOL)
@CircuitBreaker(name = "getSearchResult", fallbackMethod = "searchFailed")
@TimeLimiter(name = "getSearchResult", fallbackMethod = "searchTimeout")
public CompletableFuture<SearchResultData> getSearchResult(...) {...}
The two fallback methods have the same method signature as getSearchResult(...)
, plus a Throwable parameter.
Now, what happens is the following: In case of a timeout, searchTimeout(...)
is called as expected, using a TimeoutException in the Throwable parameter. However, when no timeout occurs, but the method throws an exception, also searchTimeout(...)
is called instead of searchFailed(...)
. The Throwable is then something else, as generated by getSearchResult(...)
.
Why is that? I would expect that timeouts lead to a call to searchTimeout(...)
and other exceptions lead to a call to searchFailed(...)
.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
When using TimeoutException in the searchTimeout(…) method signature, it works as expected. Thrown exceptions will lead to the exceptions being caught in searchFailed(…); if often enough, searchFailed() is called with a CallNotPermittedException and the protected method is not called, as expected.
In case of a timeout, searchTimeout(…) is called. If that happens often enough, searchFailed() is called with a CallNotPermittedException and the protected method is not called, as expected.
So no bug after all.
OK, good point. Both methods use Throwable. I’ll try using TimeoutException for searchTimeout(…).