[
https://issues.apache.org/jira/browse/CAMEL-27047?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Claus Ibsen resolved CAMEL-27047.
---------------------------------
Resolution: Fixed
Fixed by https://github.com/apache/camel/pull/30250 (merged to main as
5dc8fa3e0bae).
_Claude Code on behalf of davsclaus_
> camel-core - UnitOfWorkProducer (injected producers and @Produce proxies): a
> producer that throws before it calls the callback leaves the exchange in the
> inflight repository
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-27047
> URL: https://issues.apache.org/jira/browse/CAMEL-27047
> Project: Camel
> Issue Type: Bug
> Components: camel-core
> Reporter: shashank
> Assignee: shashank
> Priority: Minor
> Fix For: 4.24.0
>
>
> Found next to CAMEL-27039 (named there as a follow-up). Reproduced on main
> with a plain unit test (below).
> h3. What happens
> The producer injected with {{@EndpointInject}} / {{@Produce}} into a
> {{Producer}} field, and the producer of the {{@Produce}} proxies, is made by
> {{DefaultDeferServiceFactory}}: {{EventNotifierProducer}} around
> {{UnitOfWorkProducer}} around the producer of the endpoint.
> {{UnitOfWorkProducer}} calls the producer through a
> {{CamelInternalProcessor}} with the unit of work advice. The advice creates
> the unit of work, which adds the exchange to the inflight repository, and the
> unit of work is done (and the exchange removed) in the after advice, which
> runs from the callback. When the producer throws instead of calling the
> callback (an {{AsyncProducer}} that breaks the async contract),
> {{CamelInternalProcessor.processNonTransacted}} throws the exception on
> without running the after advice. {{EventNotifierProducer}} then sets the
> exception on the exchange and calls the callback of the caller, so the caller
> sees a failed exchange, but the unit of work is never done: the exchange
> stays in the inflight repository (and the synchronizations of the unit of
> work do not run, and no completed or failed event is fired). Each such send
> leaves one more entry in the inflight repository.
> h3. Expected
> The unit of work that {{UnitOfWorkProducer}} created is done exactly once on
> every path, as CAMEL-26953 made the sync send of the producer cache do
> ({{DefaultProducerCache.SyncSend}}): a throw before the callback fails the
> exchange and completes the send.
> h3. Reproduction
> New {{UnitOfWorkProducerProducerThrowsTest}} (camel-core): an
> {{AsyncProducer}} that throws {{IllegalStateException}} without calling the
> callback.
> * the producer that {{@EndpointInject}} injects
> ({{PluginHelper.getDeferServiceFactory(context).createProducer(endpoint)}}),
> {{process(exchange)}}: the exchange has the exception, and on main
> {{context.getInflightRepository().size()}} is 1 afterwards.
> * {{UnitOfWorkProducer}} directly: on main {{process(exchange, callback)}}
> throws, the callback is not called and the exchange stays inflight.
> * the same with an {{AssertionError}} (CAMEL-26741: an {{Error}} that is not
> a {{VirtualMachineError}} fails the exchange).
> h3. Fix
> {{UnitOfWorkProducer}} calls the producer through a small wrapper with a
> callback per send (an {{AtomicBoolean}}, as
> {{DefaultProducerCache.SyncSend}}). A throw before the callback sets the
> exception on the exchange and calls the callback, so the after advice runs
> and the unit of work is done once. A throw after the callback is thrown on as
> before (the caller handles it, CAMEL-27039). A further call of the callback
> is logged at WARN and ignored, so the unit of work is not done twice. A
> {{VirtualMachineError}} is thrown on as before. Branch
> {{camel-core-event-notifier-producer-inflight-on-throw}}.
> _Filed with Claude Code on behalf of allthingssecurity._
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)