shashank created CAMEL-27039:
--------------------------------
Summary: camel-core - EventNotifierProducer (injected producers
and @Produce proxies): a producer that calls the callback and then throws
completes the exchange twice
Key: CAMEL-27039
URL: https://issues.apache.org/jira/browse/CAMEL-27039
Project: Camel
Issue Type: Bug
Components: camel-core
Reporter: shashank
Assignee: shashank
Named as out of scope in the review of CAMEL-26953 (PR #30001, davsclaus):
{{EventNotifierProducer.process}} has the same catch that sets the exception
and calls the callback again, which CAMEL-26953 fixed in {{SendProcessor}}, the
sync send of the producer cache and the send hook. Reproduced with a plain unit
test (below).
h3. What happens
{{EventNotifierProducer}} is the outer producer that
{{DefaultDeferServiceFactory}} makes, so it is the producer injected with
{{@EndpointInject}} / {{@Produce}} into a {{Producer}} field, and the producer
of the {{@Produce}} proxies ({{ProxyHelper}}). It calls {{SendHelper.send}} and
catches {{Exception}}: it sets the exception on the exchange and calls the
callback with {{true}}. When the producer of the endpoint calls the callback
and then throws (an {{AsyncProducer}} that breaks the async contract; the unit
of work processor between them, {{CamelInternalProcessor}}, throws such an
exception on, since the callback was called first), the exchange is completed
twice: the callback of the caller is called a second time, and the exchange,
which the producer completed, now carries the exception. A sync
{{producer.process(exchange)}} on an injected producer then sees a failed
exchange although the producer completed it.
h3. Expected
The callback of a send is called exactly once ({{AsyncProcessor}}: the callback
is invoked when the processing is done), as CAMEL-26882 and CAMEL-26953 made
the other send paths do: a throw after the callback is logged at WARN and not
set on the exchange, and the send is completed once. A throw before the
callback still fails the exchange.
h3. Reproduction
New {{EventNotifierProducerProducerThrowsTest}} (camel-core): an
{{AsyncProducer}} that sets the body, calls {{callback.done(true)}} and then
throws {{IllegalStateException}}.
* {{EventNotifierProducer}} around it, without and with an event notifier: on
main the callback is called 2 times instead of 1.
* the producer that {{@EndpointInject}} injects
({{PluginHelper.getDeferServiceFactory(context).createProducer(endpoint)}}),
{{process(exchange)}}: on main the exchange has the {{IllegalStateException}}
although the producer completed it.
* control: a producer that throws before the callback fails the exchange,
callback once (passes on main too).
h3. Fix
As in {{SendProcessor.SentCallback}} (CAMEL-26953):
{{EventNotifierProducer.process}} gives the producer a small callback per send
(an {{AtomicBoolean}}) that records that it was called. A throw after it was
called is logged at WARN and the {{doneSync}} the producer passed is returned;
a throw before it sets the exception and calls the callback, as before. A
further call of the callback by the producer is passed on, as on main. An
{{Error}} is thrown on as before (CAMEL-26741). Upgrade guide (4.24): an
injected producer no longer fails the exchange in that case. Branch
{{camel-core-event-notifier-producer-callback-then-throw}}.
_Filed with Claude Code on behalf of allthingssecurity._
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)