shashank created CAMEL-27437:
--------------------------------

             Summary: camel-core - ThrottlingInflightRoutePolicy resumes the 
consumer while the circuit of a ThrottlingExceptionRoutePolicy on the same 
route is open
                 Key: CAMEL-27437
                 URL: https://issues.apache.org/jira/browse/CAMEL-27437
             Project: Camel
          Issue Type: Bug
          Components: camel-core
            Reporter: shashank
            Assignee: shashank


h3. What happens

A route can have both throttling route policies, for example 
{{routePolicy(inflightPolicy, exceptionPolicy)}}. Each policy resumes the 
consumer on its own, and neither looks at the other:

* With concurrent consumers and a failing downstream (redeliveries keep the 
exchanges in flight), {{ThrottlingInflightRoutePolicy}} suspends the consumer 
when more than {{maxInflightExchanges}} are in flight.
* The failures reach {{failureThreshold}}: {{ThrottlingExceptionRoutePolicy}} 
opens the circuit. The consumer is already suspended, so the suspend does 
nothing.
* The exchanges still in flight complete, and the inflight policy resumes the 
consumer, as it only checks its own set of suspended consumers (CAMEL-25018) 
and the route status.

The consumer now takes new messages while the circuit is open and sends them to 
the failing downstream, although the route policy docs say that while the 
circuit is open the consumer takes no new messages. The exception policy 
ignores these failures until {{halfOpenAfter}} has passed (its suspend at the 
half open check, with a {{halfOpenHandler}} that is not ready, is the first to 
stop the consumer again).

The other direction exists too: when the circuit is half opened (or closed by a 
ready {{halfOpenHandler}}), the exception policy resumes a consumer that the 
inflight policy suspended and still wants suspended. That one is milder, as the 
next completion suspends it again.

It happens in both policy orders.

h3. How to reproduce

A seda route with {{concurrentConsumers=4}}, {{maxInflightExchanges=1}}, 
{{failureThreshold=2}}, {{halfOpenAfter=60s}}, and latches that set the order 
in which four exchanges complete: after the first failure the consumer is 
suspended, after the second the circuit is open, after the third (a success) 
the consumer is started with the circuit open, and a new message reaches the 
downstream.

Found with a TLA+ model of the two policies, the redeliveries, the half open 
timer and the route controller: "while the circuit is open, no policy has 
resumed the consumer" is violated with 3 threads, in both orders.

h3. Fix

Generalise the CAMEL-25018 approach (a policy only resumes a consumer it 
suspended) to the policies of a route: a policy resumes the consumer only when 
no other policy of the route still keeps it suspended. {{RoutePolicySupport}} 
gets a protected hook that a policy overrides to say it keeps the consumer 
suspended (the inflight policy while the consumer is in its set, the exception 
policy while the circuit is open), and a check over the other policies of the 
route. The policy that lets go of the consumer does so before it checks the 
others, so when two let go at the same time, one of them resumes it (the 
exception policy reads its "letting go" flag before its state for that).

_Filed with Claude Code on behalf of allthingssecurity._



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

Reply via email to