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

Work on CAMEL-26799 started by shashank.
----------------------------------------
> camel-cluster - ClusteredRoutePolicy: a route is never started when the 
> leadership is taken before the route can be started
> ---------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-26799
>                 URL: https://issues.apache.org/jira/browse/CAMEL-26799
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-core
>            Reporter: shashank
>            Assignee: shashank
>            Priority: Major
>
> {{ClusteredRoutePolicy}} sets its leader flag when it takes the leadership 
> and then starts its routes; only a later leadership change starts or stops 
> them again. When that start does nothing, the leader never runs the route. 
> Three cases:
> *Leadership taken before the policy started.* A cluster service started on 
> its own (for example created by the application and passed to 
> {{ClusteredRoutePolicy.forNamespace(service, namespace)}}), whose view is 
> already the leader when the routes are created: the policy takes the 
> leadership when it gets the view, while it is not started yet. The start of 
> the routes then returns at once ({{isRunAllowed()}} is false), and, unlike 
> during the start of the CamelContext, nothing defers it until the 
> CamelContext has started. The route stays stopped on the leader.
> *Leadership taken while a route is added at runtime.* A route created while 
> this node is not the leader is marked {{autoStartup=false}}. If the node 
> becomes the leader before the route is added to the CamelContext, the policy 
> thread calls {{startRoute}} for a route id the CamelContext does not know 
> yet, which does nothing, and records the route as started. The route is then 
> added with {{autoStartup=false}}, and stays stopped.
> *Route removed while the policy starts it.* {{startRoute}} on the policy 
> thread waits for the route lock that {{removeRoute}} holds, then does 
> nothing, and the removed route is recorded as started again. A route added 
> later with the same id (not managed by the policy) is stopped by the policy 
> when the node loses the leadership.
> Expected: the leader starts the routes of the policy once they can be 
> started, and the policy does not keep a removed route.
> Suggested fix: defer the start until the CamelContext has started when the 
> policy is not started yet; skip a route that is not added to the CamelContext 
> yet and start it on its {{RouteAddedEvent}} when the node is the leader; 
> record a route as started only when it is still the route of the CamelContext 
> after {{startRoute}}.
> Found with Specula (TLA+ model checked against traces of the real code) and 
> confirmed with tests on the real classes.
> _Filed with Claude Code on behalf of allthingssecurity._



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

Reply via email to