shashank created CAMEL-26431:
--------------------------------

             Summary: camel-core - ThrottlingExceptionRoutePolicy: 
throttledExceptions also match a suppressed exception (such as one thrown in a 
doFinally)
                 Key: CAMEL-26431
                 URL: https://issues.apache.org/jira/browse/CAMEL-26431
             Project: Camel
          Issue Type: Bug
          Components: camel-core
            Reporter: shashank
            Assignee: shashank


Follow-up of CAMEL-26328 (apache/camel#28751), asked for in its review.

CAMEL-26328 changes the failover load balancer to match its list of exceptions 
against the exception and its causes only, as {{onException}} 
({{DefaultExceptionPolicyStrategy}}) and {{doCatch}} ({{CatchProcessor}}) do, 
with {{ObjectHelper.createExceptionIterable}}. 
{{ThrottlingExceptionRoutePolicy.hasFailed}} still checks its 
{{throttledExceptions}} with the same loop the load balancer had:

{code:java}
for (Class<?> exception : throttledExceptions) {
    // will look in exception hierarchy
    if (exchange.getException(exception) != null) {
{code}

{{Exchange.getException(Class)}} goes through 
{{ObjectHelper.getException(Class, Throwable)}}, which looks at the suppressed 
exceptions first (CAMEL-6406, a general API change) and then at the causes. So 
a failure counts towards opening the circuit when its exception is not listed 
but one of its suppressed exceptions is. Since CAMEL-25114 (4.23.0) that 
happens whenever a {{doFinally}} block throws a listed exception while the 
{{doTry}} block failed with another one; it also happens when an 
{{onException}} block fails while handling a listed exception 
({{FatalFallbackErrorHandler}}), when the {{onWhen}} of a {{doCatch}} throws, 
after a redelivery that failed with a different exception, and with a processor 
that adds a suppressed exception itself (try-with-resources).

Example: {{throttledExceptions=java.io.IOException}}, the route fails with an 
{{IllegalStateException}} from the {{doTry}} block and its {{doFinally}} 
cleanup throws an {{IOException}}: the policy counts the failure, while an 
{{onException(IOException.class)}} in the same route does not match it.

*Proposal*
* Match {{throttledExceptions}} against the exception and its causes only, with 
{{ObjectHelper.createExceptionIterable}}, so the policy, the failover load 
balancer, {{onException}} and {{doCatch}} agree.
* Upgrade guide entry (a route that relied on the suppressed match adds the 
type of the exception the route fails with), and tests for the {{doFinally}} 
case with controls (a listed exception thrown directly and as a cause still 
count).

_Filed with Claude Code on behalf of allthingssecurity._



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to