shashank created CAMEL-27517:
--------------------------------
Summary: camel-netty - a TimeoutCorrelationManagerSupport bean
used by two producers is stopped when one of them stops, so the requests of the
other never time out or are completed by that stop
Key: CAMEL-27517
URL: https://issues.apache.org/jira/browse/CAMEL-27517
Project: Camel
Issue Type: Bug
Components: camel-netty
Reporter: shashank
Assignee: shashank
h3. What happens
A correlation manager is a bean ({{correlationManager=#myManager}}), so every
producer of that endpoint (two routes that send to the same URI, or a producer
cache) and every endpoint that refers to the same bean use the same instance.
Each producer starts it in {{doStart}} and stops it in {{doStop}}, and
{{ServiceSupport}} start/stop are not counted. When one producer stops (its
route is stopped, for example), a {{TimeoutCorrelationManagerSupport}} is
stopped under the producers that still run:
* the requests of the other producers that wait for their reply are completed
with an {{ExchangeTimedOutException}} by the drain of CAMEL-27335 (before
CAMEL-27335 they were dropped and never completed), even though their channel
is open and the reply may still come;
* the purge task is cancelled, so the requests the other producers send next
stay in the map of a stopped manager and never time out; with a server that
does not answer, the exchange waits forever;
* when the stopped producer starts again, the manager gets a new, empty map, so
the states the other producers put in the old one are not found by their reply.
h3. How to reproduce
Two producers of one endpoint with {{correlationManager=#myManager}} (timeout
300 ms) and a server that never replies. Stop the first producer: the manager
is stopped while the second runs. A request of the second producer is not
completed after 10 s. With a server that replies on demand and a 60 s timeout:
the second producer sends, the first producer is stopped and started again, the
server replies: the exchange was already failed with
{{ExchangeTimedOutException}} by the stop, and the reply is ignored.
Found with a TLA+ model of the producer, the timeout map, the worker pool and
stop/start with two producers sharing the bean ("a running producer has a
started manager" fails), and reproduced against the real producer.
h3. Fix
The producers take a reference on a {{TimeoutCorrelationManagerSupport}}: the
first producer that starts starts it, and only the last one that stops stops it
(and drains the requests that still wait, as CAMEL-27335 does). A producer
whose start failed before it took its reference does not stop it. Other
correlation managers (the default one, created by each producer, and custom
implementations of {{NettyCamelStateCorrelationManager}}) are started and
stopped by each producer as before. {{putState}} now fails the request with an
{{IllegalStateException}} when the manager is not started (for example a bean
stopped by the application while a producer runs). It checks again after the
put: when the manager stopped while the state was put (its stop drained the map
before or after the put, or it also started again with a new map), the state is
taken back and the request fails, unless the drain already completed it; the
state decides which of the two completes the exchange, so it is completed once.
_Filed with Claude Code on behalf of allthingssecurity._
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)