shashank created CAMEL-27439:
--------------------------------

             Summary: camel-core - Aggregate EIP: a route stop and start resets 
the redelivery count of recovered exchanges, so they get more than 
maximumRedeliveries attempts
                 Key: CAMEL-27439
                 URL: https://issues.apache.org/jira/browse/CAMEL-27439
             Project: Camel
          Issue Type: Bug
          Components: camel-core
            Reporter: shashank
            Assignee: shashank


h3. What happens

With a recoverable aggregation repository (such as 
{{JdbcAggregationRepository}}) and {{maximumRedeliveries}} plus 
{{deadLetterUri}}, the recover task of {{AggregateProcessor}} counts the 
redeliveries of each recovered exchange in an in-memory map 
({{redeliveryState}}). The dead letter decision reads only that map. 
{{AggregateProcessor.doStop}} clears it, so when the route is stopped and 
started, the next recover check finds no count and starts again from 1:

* the recovered exchange is processed up to {{maximumRedeliveries}} more times 
before it is moved to the dead letter channel;
* the copy sent to the dead letter channel has a {{CamelRedeliveryCounter}} 
lower than the number of redeliveries that happened.

Example with {{maximumRedeliveries=2}} and a route that always fails: without a 
restart the exchange is processed 3 times (the first attempt and 2 
redeliveries) and the dead letter copy has {{CamelRedeliveryCounter=2}}. With a 
route stop and start after the first redelivery, it is processed 4 times, and 
the dead letter copy still has {{CamelRedeliveryCounter=2}}.

h3. How to reproduce

A test with {{JdbcAggregationRepository}} on H2, {{maximumRedeliveries=2}}, a 
dead letter endpoint and a route that always throws. After the first redelivery 
the route is stopped and started: 4 processing attempts before the dead letter 
channel instead of 3 (3 runs out of 3). The same happens in camel-core with the 
in-memory {{KeyValueAggregationRepository}}.

Found with a TLA+ model of the recovery of the JDBC aggregation repository 
(route restart, crash, several instances).

h3. Fix

Keep the redelivery counts across {{doStop}}/{{doStart}} and clear them in 
{{doShutdown}}. As the counts are no longer cleared by a stop, the recover task 
drops, after each scan, the count of an exchange that the scan did not return 
(for example confirmed by another node).

Not changed: the count is only in memory, so after the route is removed, the 
CamelContext is stopped, or the JVM restarts (or crashes), a recovered exchange 
gets up to {{maximumRedeliveries}} attempts again. The docs will say so.

_Filed with Claude Code on behalf of allthingssecurity._



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

Reply via email to