shashank created CAMEL-26305:
--------------------------------
Summary: camel-jgroups-raft - removing the route that consumes
from an endpoint closes the channel and the Raft log that its producer still
uses, so the node leaves the cluster
Key: CAMEL-26305
URL: https://issues.apache.org/jira/browse/CAMEL-26305
Project: Camel
Issue Type: Bug
Components: camel-jgroups
Reporter: shashank
Assignee: shashank
The producers and consumers of a {{jgroups-raft:}} endpoint share the
{{RaftHandle}} the endpoint created (from {{channelProperties}} or the default
configuration, no {{raftHandle}} on the component). When a route is removed,
the core stops the endpoint of its consumer ({{RouteService.doShutdown}}), also
when other routes still use the endpoint, and {{JGroupsRaftEndpoint.doStop}}
closes the handle's channel and its Raft log regardless of the producers and
consumers still connected (main c536c99caaaa, lines 122 and 127). The node
leaves the Raft cluster and the producer route's {{set}} calls fail until the
removed route is added again. As each endpoint creates its own handle with the
endpoint's {{raftId}}, a node that both changes the state machine and listens
to role changes uses the same uri for its producer and its consumer, so they
share the endpoint: removing the role-change route (a route reload, a removed
route template or Kamelet, JMX or the control bus) takes the node out of the
cluster.
CAMEL-25883 fixed this for the {{raftHandle}} of the component and left the
handle an endpoint creates itself unchanged.
*Fix*: the endpoint closes its own handle (channel and log) at stop only when
no producer or consumer is connected; otherwise the last one that disconnects
closes it once the endpoint is stopped. A restarted endpoint keeps its handle
while the channel is still open. A connect is now counted once it succeeded (as
in camel-jgroups), so a producer whose connect failed does not keep the handle
open. The handles of the component or a {{raftHandle}} bean are unchanged.
*Tests*: new {{JGroupsRaftRemoveRouteTest}} (three nodes A, B, C in the JVM
with {{raftABC.xml}}; node A has a producer and a role-change consumer on the
same uri): {{removeConsumerRouteKeepsTheHandleOfTheProducer}} and
{{removeBothRoutesClosesTheHandle}} fail on main (3 runs: {{the producer still
uses the channel ==> expected: <true> but was: <false>}}), and
{{removeConsumerRouteThenAddItAgainKeepsTheHandle}} (3 runs: {{the re-added
consumer uses the handle of the producer}}); all pass with the fix. With the
fix camel-jgroups-raft has 22 tests, 0 failures.
*How it was found*: a code sweep for endpoints whose {{doStop}} releases
something that other routes on the same uri still use, after a random
lifecycle-sequence harness found the same kind of defect in camel-disruptor
(CAMEL-26286).
*Affected*: main, camel-4.22.x, camel-4.18.x and camel-4.14.x (same {{doStop}};
read, not run).
_Filed with Claude Code on behalf of allthingssecurity._
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)