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

Work on CAMEL-27355 started by shashank.
----------------------------------------
> camel-rocketmq - an InOut request whose send succeeds while the producer 
> stops is never completed, and a request that passed the running check creates 
> a reply manager after the stop
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-27355
>                 URL: https://issues.apache.org/jira/browse/CAMEL-27355
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-rocketmq
>            Reporter: shashank
>            Assignee: shashank
>            Priority: Major
>
> h3. What happens
> Two gaps of the request-reply code of {{RocketMQProducer}} around a stop, the 
> same as CAMEL-27321 and CAMEL-27339 close in camel-jms and camel-sjms:
> * *A request registered during or after the stop is never completed.* The 
> producer registers the handler of an InOut request in the {{onSuccess}} 
> callback of the asynchronous send, so it can come at any time relative to the 
> stop. {{ReplyTimeoutMap.doStop}} drains the map (each handler is completed 
> with a {{RejectedExecutionException}}) and then {{DefaultTimeoutMap.doStop}} 
> cancels the purge task and clears the map. A handler added between the drain 
> and the clear is removed without being completed, and one added after the 
> stop stays in the stopped map, where nothing evicts it. The exchange never 
> completes, and a synchronous caller waits for ever.
> * *A reply manager created after the producer stopped.* {{process}} checks 
> {{isRunAllowed()}}, then converts the body and calls {{initReplyManager()}}. 
> A request that passed the check before the stop finds {{started=false}} after 
> it, takes the producer's lock (held by the stop, so it waits for the stop to 
> end) and creates and starts a new reply manager: a {{DefaultMQPushConsumer}} 
> on the reply topic and a timeout checker thread. Then the send fails with a 
> {{NullPointerException}} (the stop set {{mqProducer}} to null). Nothing stops 
> the reply manager until the producer is started and stopped again; a producer 
> that is not started again (a removed route, a stopped {{ProducerTemplate}}) 
> leaks it for good.
> The timeout tasks dropped by a forced executor shutdown (the third part of 
> CAMEL-27321) do not apply here: {{ReplyTimeoutMap}} completes the timed out 
> handlers on the purge thread and the drained ones on the stopping thread, 
> without a separate executor.
> h3. How to reproduce
> Register a reply on a {{RocketMQReplyManagerSupport}} after it stopped, or 
> from a listener of the map while the stop drains it: the exchange is never 
> completed. Hold an InOut request in the conversion of its body, stop the 
> producer, and let the request continue: {{createReplyManager}} is called 
> after the stop, and with a name server the new reply manager (its consumer 
> and the thread {{RocketMQReplyManagerTimeoutChecker[topic]}}) keeps running.
> Found with a TLA+ model of the producer, its reply manager and the stop.
> h3. Fix
> * {{ReplyTimeoutMap}} uses its own lock (passed to {{DefaultTimeoutMap}}) and 
> a {{closed}} flag set under that lock before the drain. A handler that is 
> added once the map is closed is completed at once, as the drain would have 
> done (the request has been sent, so it cannot be refused any more).
> * {{initReplyManager}} checks {{isRunAllowed()}} again under the producer's 
> lock and fails the request with {{RejectedExecutionException}} instead of 
> creating a reply manager.
> _Filed with Claude Code on behalf of allthingssecurity._



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

Reply via email to