[
https://issues.apache.org/jira/browse/CAMEL-15928?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17251773#comment-17251773
]
Alex Liroyd commented on CAMEL-15928:
-------------------------------------
Hello, I did a small investigation, and I want to insist that it's a critical
bug and not a major improvement:).
Regarding initial issues - resilience4J provides ability to select explicitly,
which errors should trigger circuit breaker and which should not.
And you can specify TimeoutException as one of those. And it works perfectly,
when using pure resilience4J. If you specifies TimeoutException, it will
trigger CB, if no, then no.
Camel-resilience4j also provides ability to select list off exceptions. But
it's not possible to select TimeoutException as one for triggering CB. Yes, you
can provide it for config, but camel itself will never treat it correctly.
*And I found another issue with fallback.* Basically fallback for such camel
routes will be executed only in one case - yes, only in case of
TimeoutException. Example:
{code:java}
<route id="myROute">
<from uri="direct:myURI"/>
<circuitBreaker configurationRef="{{myConfig}}">
<to uri="myExecutionRoute"/>
<onFallback>
<bean method="test" ref="myFallbackBean"/>
</onFallback>
</circuitBreaker>
</route>
{code}
For such configuration, onFallback will be executed only when we receive
TimeoutException.
The rootcause for both issue is the same - currently ResilienceProcessor wraps
task CB first, and only after that wraps it in TimeLimiter.
Regarding fallback - currently it's called like:
{code:java}
Try.ofCallable(task).recover(fallbackTask).andFinally(() ->
callback.done(false)).get();
{code}
_recover_ executes _fallback_ only if - _this.isFailure()_,
_Try.ofCallable(task)_ returns _Failure_ only for TimeoutExceptions. All other
exceptions will be catched by _MethodInfo#MethodInvocation#proceed_ - therefore
it will be success for every other exception.
I will try to find a solution, but any help would be appreciable.
> TimeoutException does not trigger Resilience4j circuit breaker
> --------------------------------------------------------------
>
> Key: CAMEL-15928
> URL: https://issues.apache.org/jira/browse/CAMEL-15928
> Project: Camel
> Issue Type: Improvement
> Components: came-core, eip
> Affects Versions: 3.4.4
> Reporter: Alex Liroyd
> Priority: Major
> Fix For: 3.8.0
>
> Attachments: hot_fix.diff
>
>
> Currently Timeout exceptions does not trigger circuit breaker. But they
> should. I don't want to continue spam my server, if it slightly started dying.
> I tried to hot-fix in the next way - [^hot_fix.diff]
> The idea behind patch is next. Currently we wrap our call with circuit
> breaker and only after that with time limiter. So, circuit breaker doesn't
> know anything about time-outs.
> And basically I do opposite - initially wrap call with time limiter and only
> after that, wrap it with circuit breaker. So circuit breaker will aware about
> time-out exception and can react properly.
> The issue which I have afterward, that, for cases when circuit breaker was
> open, I started receiving blank 200 OK response.
> I tried to fix it by removing recover(fallbackTask) part at all:
>
> {code:java}
> // Try.ofCallable(task).recover(fallbackTask).andFinally(() ->
> callback.done(false)).get(); //old code
> Try.ofCallable(task).andFinally(() -> callback.done(false)).get(); // new
> line of code
> {code}
> And seems like it works fine. But tests are failing, and I'm not sure how
> exactly it should be fixed.
> Also another fix, which seems like works fine and tests are not failing:
> CircuitBreakerFallbackTask
>
> {code:java}
> } else if (throwable instanceof CallNotPermittedException) {
> // the circuit breaker triggered a call rejected
>
> exchange.setProperty(CircuitBreakerConstants.RESPONSE_SUCCESSFUL_EXECUTION,
> false);
> exchange.setProperty(CircuitBreakerConstants.RESPONSE_FROM_FALLBACK,
> false);
> exchange.setProperty(CircuitBreakerConstants.RESPONSE_SHORT_CIRCUITED,
> true);
> exchange.setProperty(CircuitBreakerConstants.RESPONSE_REJECTED, true);
> throw RuntimeExchangeException.wrapRuntimeException(throwable); // new
> line of code
> //return exchange; // old code
> {code}
>
>
> Please, assist.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)