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

Work on CAMEL-27502 started by shashank.
----------------------------------------
> camel-hazelcast - stopping a transacted hazelcast-seda route rolls back an 
> exchange that is still being routed, so its message is consumed again
> ------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-27502
>                 URL: https://issues.apache.org/jira/browse/CAMEL-27502
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-hazelcast
>            Reporter: shashank
>            Assignee: shashank
>            Priority: Major
>
> h3. What happens
> When the route of a transacted ({{transacted=true}}) Hazelcast SEDA consumer 
> is stopped (route stop, CamelContext stop, graceful shutdown) while an 
> exchange is being routed, {{HazelcastSedaConsumer.doStop}} shuts its threads 
> down with {{ExecutorServiceManager.shutdownGraceful}}. That waits 
> {{shutdownAwaitTermination}} (10 s by default) and then interrupts the 
> threads. The {{DefaultShutdownStrategy}} stops the consumer first and only 
> then waits for the exchanges in flight (45 s by default), so an exchange that 
> takes longer than 10 s is interrupted although the shutdown would still wait 
> for it:
> * when the route continues on another thread ({{threads()}}, an asynchronous 
> producer), the interrupt ends the wait of the consumer thread for the 
> exchange: the exchange gets an {{InterruptedException}}, the consumer rolls 
> back the transaction (the message goes back to the head of the queue), and 
> the exchange goes on and completes. The message is processed again after the 
> restart, or by a consumer on another member.
> * when the route is synchronous, the interrupt aborts it at 10 s, and its 
> transaction is rolled back too. Whatever the route did before is done again.
> The {{transacted}} option promises that the message is removed when the 
> transaction commits, which happens when the processing is complete. The 
> interrupt arrived with CAMEL-25840 (the consumer waits for its threads before 
> it stops), which was right to wait for the poll; the interrupt after 10 s is 
> what rolls back the exchange.
> h3. How to reproduce
> A transacted route 
> {{from("hazelcast-seda:q?transacted=true").threads(1).process(slow)}} where 
> the step takes longer than {{shutdownAwaitTermination}}. Stop the route while 
> the step runs: the log shows "Forcing shutdown of ExecutorService", an 
> {{InterruptedException}} on the exchange, then "Waiting as there are still 1 
> inflight"; the step completes, the queue holds the message again, and the 
> next start processes it a second time.
> Found with a TLA+ model of the consumer loop (transactions, timeouts, 
> rollbacks, asynchronous continuations, stop and start).
> h3. Fix
> In transacted mode, the stop first waits until no consumer thread polls or 
> routes an exchange, at most the timeout of the shutdown strategy, and only 
> then shuts the threads down as before. A thread counts itself (under a lock, 
> together with the {{isRunAllowed()}} check) before it polls, so the stop 
> either waits for it or the thread does not poll. An exchange that is still 
> being routed when the shutdown timeout expires (or when the shutdown strategy 
> times out) is rolled back as before. Once the shutdown strategy has timed out 
> and stops the remaining consumers at once (forced), the stop does not wait 
> again, and a consumer thread that stops the consumer itself (a route policy 
> when its exchange completes) does not wait for itself. The delay after a 
> failed exchange ({{onErrorDelay}}) is not waited for, and it is skipped when 
> the consumer is stopping (a thread that the stop no longer waits for must not 
> use the delay scheduler that the stop shut down). The non-transacted consumer 
> is not changed.
> Not changed here: a message that always fails is taken again after every 
> rollback without a limit (the route can use a dead letter channel), and the 
> non-transacted consumer with an asynchronous route keeps polling while its 
> exchanges are in flight (as camel-seda does).
> _Filed with Claude Code on behalf of allthingssecurity._



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

Reply via email to