[ 
https://issues.apache.org/jira/browse/CAMEL-27536?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

shashank updated CAMEL-27536:
-----------------------------
    Fix Version/s: 4.25.0

> camel-kafka - a suspended route with the pausable EIP keeps consuming: the 
> consumer listener resumes the paused partitions on the next poll
> -------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-27536
>                 URL: https://issues.apache.org/jira/browse/CAMEL-27536
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-kafka
>            Reporter: shashank
>            Assignee: shashank
>            Priority: Major
>             Fix For: 4.25.0
>
>
> h3. What happens
> A route with the pausable EIP ({{.pausable(new KafkaConsumerListener(), 
> check)}}) keeps consuming after it was suspended (route controller, JMX, or 
> {{ThrottlingExceptionRoutePolicy}} opening its circuit), as long as the check 
> of the pausable EIP holds, which is the normal case.
> # {{KafkaConsumer.doSuspend}} sets the state of each fetcher task to 
> PAUSE_REQUESTED.
> # After the next poll {{KafkaFetchRecords.updateTaskState}} pauses the 
> assigned partitions and sets PAUSED. {{isKafkaPaused()}} now returns true.
> # On the next poll loop iteration {{KafkaFetchRecords.startPolling}} calls 
> {{KafkaConsumerListener.afterConsume}} before anything looks at the state, 
> and with the check true it calls {{consumer.resume(consumer.assignment())}}. 
> {{updateTaskState}} sees PAUSED and does nothing.
> # The next poll returns records again and they are handed to the suspended 
> route. This repeats on every poll, while the state stays PAUSED and 
> {{isKafkaPaused()}} (JMX, health, dev console) still reports the consumer as 
> paused.
> The same happens to a consumer that starts or reconnects while suspended (for 
> example a route started with an open circuit): the rebalance listener pauses 
> the newly assigned partitions inside the poll (CAMEL-25313), and 
> {{afterConsume}} resumes them right after.
> So with the pausable EIP in a route, a circuit breaker or an operator cannot 
> stop the consumption: records keep flowing into the failing route and are 
> committed past.
> h3. How to reproduce
> The {{KafkaConsumerSuspendResumeTest}} setup ({{MockConsumer}}) with 
> {{.pausable(new KafkaConsumerListener(), o -> true)}} in the route: consume a 
> record, suspend the route, wait until {{isKafkaPaused()}} is true, add a 
> record. It is handed to the route while the route is suspended. The same 
> happens against a real single-node Kafka 4.3.1 broker.
> Found with a TLA+ model of the fetcher state machine (suspend/resume requests 
> at any point, rebalances, breakOnFirstError reconnects) together with the 
> pausable EIP listener.
> h3. Fix
> {{KafkaFetchRecords}} does not call the listener's {{afterConsume}} while the 
> state is PAUSED. In that state the poll returns no records (the partitions 
> are paused; a rebalance or reconnect sets PAUSE_REQUESTED and pauses them 
> again), so the listener has nothing to protect. While a pause is requested 
> but not applied yet, the listener runs as before and {{updateTaskState}} 
> applies the pause in the same iteration. In an iteration where the listener 
> was skipped, {{updateTaskState}} is not called either, so a resume of the 
> route that lands while the records of that poll are processed is applied on 
> the next iteration, after the listener: it does not resume the partitions 
> while the check fails.
> Semantics, with one consumer per route ({{consumersCount=1}}): a suspend wins 
> over the check of the pausable EIP (a suspended route consumes nothing, 
> whatever the check says); resuming the route does not override the check 
> (while the check fails the listener keeps the consumer paused, and 
> consumption starts once it holds; unchanged).
> Related, not changed here: with {{consumersCount}} above 1 all tasks share 
> one {{KafkaConsumerListener}}, which keeps only the Kafka consumer of the 
> task that connected last. With tasks A and B where the listener keeps A's 
> consumer: a rebalance of B while the route is suspended makes B call the 
> listener, which resumes A's consumer (from B's thread); A is PAUSED and 
> neither calls the listener nor pauses again, so A consumes while the route 
> stays suspended (also on main; follow-up JIRA). With 
> {{autoCommitEnable=true}} a suspend and resume can deliver records again that 
> were processed after the last auto commit, since the resume seeks to the 
> committed offset (allowed by at-least-once).
> _Filed with Claude Code on behalf of allthingssecurity._



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

Reply via email to