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

Work on CAMEL-27583 started by shashank.
----------------------------------------
> camel-core - RebalancingCamelClusterService: one failed rebalancing pass ends 
> the rebalancing for good, and each stop and start of the service adds another 
> chain of passes
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-27583
>                 URL: https://issues.apache.org/jira/browse/CAMEL-27583
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-core
>            Reporter: shashank
>            Assignee: shashank
>            Priority: Minor
>             Fix For: 4.24.0
>
>
> h3. What happens
> {{RebalancingCamelClusterService}} runs its rebalancing passes on a single 
> thread scheduled executor. Each pass schedules the next one at its very end 
> ({{rescheduleAfterDelay}}). Two problems with that loop:
> * *One exception ends the rebalancing for good.* The pass has no catch around 
> it, and {{partitionList()}} calls {{getNamespaces()}} of the delegate outside 
> of any try. If anything in a pass throws (an {{Error}}, or a 
> {{RuntimeException}} from {{getNamespaces()}} of a delegate), the pass never 
> reaches the reschedule, the executor swallows the exception, and no pass runs 
> again. The service still reports Started, so nothing shows that partitions 
> are no longer balanced: a member that held all the partitions keeps them.
> * *Each stop and start of the service adds a chain of passes.* {{doStop}} 
> calls {{ExecutorServiceManager.shutdown}}, and a scheduled executor still 
> runs its delayed tasks after a plain shutdown. After a start, the old pending 
> pass runs and schedules its next pass on the new executor, next to the chain 
> that {{doStart}} began. Measured with a period of 100 ms: about 7 passes per 
> second, 12 after one restart, 24 after two. In the window a pass on the old 
> thread can also run at the same time as a pass on the new one. No wrong 
> decision was seen, only extra passes and API calls of the delegate.
> h3. How to reproduce
> A {{RebalancingCamelClusterService}} in a {{DefaultCamelContext}} over a 
> small in-memory preemptive cluster service with one view.
> * Make {{getNamespaces()}} of the delegate throw once: no pass runs 
> afterwards, and a view that is then disabled is never enabled again, although 
> the service is Started.
> * Stop and start the service three times: passes keep running on the thread 
> of the executor of the previous start, and more than one pass runs per period.
> Found with a TLA+ model of the rebalancing service (the member that held both 
> partitions keeps them for ever once the loop died), and reproduced against 
> the real class.
> h3. Fix
> * The pass is wrapped in a catch of {{Throwable}}. The first failure is 
> logged at WARN, repeated failures at DEBUG, and the next pass is scheduled in 
> a {{finally}}.
> * {{doStop}} uses {{shutdownNow}}, which drops the pending pass, and a pass 
> only schedules the next one on the executor it ran on, while that is still 
> the executor of the service. A pass scheduled by a stop that lands between 
> that check and the schedule is dropped by the stopped executor (with an Abort 
> policy the RejectedExecutionException is caught).
> The rebalancing decisions themselves are unchanged.
> _Filed with Claude Code on behalf of allthingssecurity._



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

Reply via email to