Saravanakumar Selvaraj created CAMEL-27758:
----------------------------------------------

             Summary: camel-alibaba-oss, camel-alibaba-mns: OSSProducer keeps a 
closed client, and initClient on a stopped endpoint leaves a client open
                 Key: CAMEL-27758
                 URL: https://issues.apache.org/jira/browse/CAMEL-27758
             Project: Camel
          Issue Type: Bug
    Affects Versions: 4.23.0
            Reporter: Saravanakumar Selvaraj


I checked the code of main at e785ba78ad52, aliyun-sdk-mns 2.0.0 and 
alibabacloud-oss-v2 0.6.1.

A stop and start of a route does not stop its endpoint, so the client stays 
open. A suspend and resume of the CamelContext does not stop it either. In 
these cases, the consumers and producers of both components keep using the open 
client of the endpoint.

The removal of a route differs. RouteService.doShutdown stops and shuts down 
the endpoint of its consumer. It does so also when another route still sends to 
that endpoint, which then stays registered. removeRoute, the JMX operation 
remove of a route, and a route reload with removeAllRoutes=false can remove the 
consumer route alone. CAMEL-26302 (camel-ehcache) and CAMEL-26304 
(camel-jgroups) fixed the same case in their components.

camel-alibaba-oss:

- OSSProducer keeps the client of its first exchange in a field, and nothing 
resets it. OSSEndpoint.doStop closes the client that the endpoint created.
- If the other route's producer had an exchange before the removal, it sends 
each request on the closed client. The SDK fails each request with an 
OperationException, whose root cause is the IllegalStateException "Connection 
pool shut down".
- The failures go on after addRoutes adds the consumer route again. They end 
when the sending route restarts, as SendProcessor then creates a new producer.
- A producer that a toD, a recipientList or a ProducerTemplate pools for that 
endpoint fails the same way.

camel-alibaba-mns and camel-alibaba-oss:

- initClient creates a client whenever the endpoint holds none, whatever the 
state of the endpoint. Only doStop closes it.
- BaseService.stop does nothing for an endpoint that has already stopped or 
shut down. A client that initClient creates on a stopped endpoint stays open 
after the CamelContext stops, unless the endpoint starts again.
- MNSProducer calls initClient for each exchange. After the removal above, its 
next exchange creates such a client. For MNS, that client holds a reference to 
the ServiceClient that aliyun-sdk-mns 2.0.0 shares, so its HttpAsyncClient 
stays open. Its I/O reactor thread is not a daemon thread.
- OSSProducer creates such a client when its first exchange comes after the 
removal.

Two smaller points, after a stop that timed out or a stop of the endpoint:

- OSSConsumer keeps its set of the objects in progress in the consumer 
instance. After a route stop that timed out, the next start creates a new 
consumer with an empty set. That consumer can take an object whose first 
exchange still runs.
- MNSConsumer.processCommit reads the client of the endpoint when the exchange 
completes. When the endpoint created the client, an exchange that completes 
after the endpoint stopped can find no client there. The delete then fails with 
a NullPointerException, so the message returns to the Active state after the 
queue's VisibilityTimeout.

Proposed change:

- The endpoint keeps its client while another route still uses it, as 
CAMEL-26302 and CAMEL-26304 did for their resources.
- OSSProducer gets the client from initClient for each exchange, as MNSProducer 
does.
- The set of the objects in progress moves to the endpoint, as in camel-aws2-s3.
- MNSConsumer.processCommit gives a clear message when the endpoint has no 
client.

_Claude Code on behalf of saravanakumar1987_




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

Reply via email to