shashank created CAMEL-26304:
--------------------------------
Summary: camel-jgroups - removing the route that consumes from an
endpoint closes the channel that its producer still uses, so every send of the
other routes fails with "channel is closed"
Key: CAMEL-26304
URL: https://issues.apache.org/jira/browse/CAMEL-26304
Project: Camel
Issue Type: Bug
Components: camel-jgroups
Reporter: shashank
Assignee: shashank
The producers and consumers of a {{jgroups:}} endpoint share the channel the
endpoint created (no {{channel}} option on the endpoint or the component); they
count their connects, and the last one that stops disconnects it
({{JGroupsEndpoint.connect/disconnect}}). When a route is removed, the core
stops the endpoint of its consumer ({{RouteService.doShutdown}}), also when
other routes still use the endpoint, and {{JGroupsEndpoint.doStop}} closes the
channel regardless of that count (main c536c99caaaa, line 184). A closed
{{JChannel}} cannot be used again, so every send of the routes that produce to
the same uri fails with {{IllegalStateException: channel is closed}} until the
removed route is added again (a new consumer creates and connects a new
channel). Example: {{from("direct:orders").to("jgroups:orders")}} and
{{from("jgroups:orders").to(...)}} on the same node, as in
{{JGroupsSharedChannelTest}}; removing the consumer route (a route reload, a
removed route template or Kamelet, JMX or the control bus) breaks the producer
route.
CAMEL-25852 fixed this for the channel of the component and left the channel an
endpoint creates itself unchanged.
*Fix*: the endpoint closes its own channel 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 channel while it is
still open (before, it created a new one). The channels of the component or a
{{channel}} bean are unchanged.
*Tests*: new {{JGroupsRemoveRouteTest}} (two endpoints of one cluster in the
JVM): {{removeConsumerRoute}}, {{removeBothRoutesClosesTheChannel}} and
{{removeConsumerRouteThenAddItAgain}} fail on main (3 runs:
{{IllegalStateException: channel is closed}} on the send after the removal,
{{the producer still uses the channel ==> expected: <true> but was: <false>}},
and {{the re-added consumer uses the channel of the producer}}) and pass with
the fix. With the fix camel-jgroups has 36 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)