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

Work on CAMEL-27416 started by shashank.
----------------------------------------
> camel-base-engine - AsyncProcessorAwaitManager: interrupt can fail an 
> exchange that already returned as done, and a second thread waiting for the 
> same exchange hides the first
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-27416
>                 URL: https://issues.apache.org/jira/browse/CAMEL-27416
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-core
>            Reporter: shashank
>            Assignee: shashank
>            Priority: Major
>
> h3. What happens
> {{DefaultAsyncProcessorAwaitManager.interrupt(exchange)}} (JMX 
> {{interrupt(exchangeId)}}, and the stop of the CamelContext with 
> {{interruptThreadsWhileStopping}}) reads the entry of the blocked thread, 
> builds the WARN line with the blocked thread and the message history, and 
> only then sets {{RejectedExecutionException}}, marks the exchange interrupted 
> and counts the latch down. When the callback of the processor fires in 
> between, the thread has already returned the exchange to its caller as done. 
> The interrupt then fails it and marks it interrupted while the caller goes on 
> with it: a consumer can report a completed exchange as failed, and later 
> steps see {{isInterrupted()}} and stop routing.
> The blocked threads are kept in a map keyed by the exchange. Two threads can 
> wait for the same exchange: a thread waits in {{process()}} while the 
> exchange goes on on another thread, which calls a step that waits for it too 
> (for example {{ProducerTemplate.send(uri, exchange)}}). The second thread 
> replaces the entry of the first, and removes it when it returns. The first 
> thread is still blocked but no longer listed: {{size()}}, {{browse()}}, JMX 
> and the blocked console do not show it, {{interrupt}} does not find it, and 
> the stop logs that there are no inflight threads.
> {{doStop}} also clears the entries after its interrupts, so a thread that 
> started to wait while the stop ran is no longer listed either.
> h3. How to reproduce
> A processor whose callback fires while {{interrupt(exchange)}} builds its 
> WARN line: the waiting thread returns the exchange without an exception, and 
> afterwards the exchange has {{RejectedExecutionException}} and 
> {{isInterrupted() == true}}. Two threads waiting for one exchange: {{size()}} 
> is 1 while both are blocked, and 0 after the second returned while the first 
> is still blocked; {{interrupt(exchange)}} and {{stop()}} do not release it.
> Found with a TLA+ model of the await manager.
> h3. Fix
> One entry per waiting thread. The entry decides under its own lock whether 
> the interrupt still applies (the thread has not returned and the callback has 
> not fired), and the thread marks its entry finished under that lock before it 
> returns. {{interrupt(exchange)}} interrupts every thread that waits for the 
> exchange. {{doStop}} no longer clears the entries; each thread removes its 
> own.
> _Filed with Claude Code on behalf of allthingssecurity._



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

Reply via email to