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

Claus Ibsen resolved CAMEL-27587.
---------------------------------
    Resolution: Fixed

Fixed by https://github.com/apache/camel/pull/30909, squash-merged into main.

_Claude Code on behalf of davsclaus_

> camel-master - a start of the delegated consumer that finishes after the 
> master consumer was stopped and started again replaces the new delegated 
> consumer, which then runs on after the leadership is lost
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-27587
>                 URL: https://issues.apache.org/jira/browse/CAMEL-27587
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-master
>            Reporter: shashank
>            Assignee: shashank
>            Priority: Major
>             Fix For: 4.24.0
>
>
> h3. What happens
> When {{MasterConsumer}} holds the leadership, a background task creates and 
> starts the delegated consumer. If the master consumer is stopped while that 
> start is still running, {{doStop}} cancels the task with an interrupt and 
> shuts the leadership thread pool down without waiting. A delegated consumer 
> whose start does not stop on the interrupt (a client connect that catches 
> {{InterruptedException}}, or blocking I/O) keeps starting, and {{stop()}} 
> returns.
> When the same master consumer is started again (for example with the start 
> and stop operations of its MBean), {{doInit}} creates a new thread pool and 
> the cluster view reports the current leadership, so a new task starts a 
> second delegated consumer and publishes it. When the first start then 
> completes, it checks only that the leadership is taken and that the master 
> consumer may run. Both are true again, so it publishes the first delegated 
> consumer over the second. The second one keeps running and nothing references 
> it: losing the leadership stops only the first, so the second keeps consuming 
> on a node that is no longer the leader, next to the consumer of the new 
> leader. A later stop does not stop it either.
> Without the restart, the start finishes after {{stop()}} returned, so the 
> delegated consumer is started while the route is already stopped, until the 
> task sees that and stops it. And a late start of a stopped master consumer 
> whose route was started again (a new master consumer) shuts down the 
> delegated endpoint, which the consumer of the new master consumer uses.
> h3. How to reproduce
> A delegated consumer whose start blocks on a latch and ignores interrupts, 
> and a test cluster view whose leadership the test sets. Take the leadership, 
> stop and start the same {{MasterConsumer}} while the start blocks, wait for 
> the second delegated consumer to start, then release the first start: both 
> delegated consumers run, and after the leadership is lost one of them still 
> runs.
> Found with a TLA+ model of the start attempts across a stop and start of the 
> same master consumer.
> h3. Fix
> * The start task publishes its delegated consumer only while it is still the 
> current task and no delegated consumer is set. Otherwise it stops its own 
> consumer, and not the delegated endpoint, which a newer consumer may use. 
> Stopping a consumer also stops the processor of the route, so when another 
> delegated consumer runs, the processor is started again.
> * {{doStop}} waits for a start that is still running, at most the 
> shutdownAwaitTermination of the ExecutorServiceManager (10 seconds by 
> default) and as long again after interrupting it, before it stops the 
> delegated consumer.
> _Filed with Claude Code on behalf of allthingssecurity._



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

Reply via email to