shashank created CAMEL-27354:
--------------------------------
Summary: camel-netty - with reuseChannel=true a failed exchange
never gives its channel back to the producer pool
Key: CAMEL-27354
URL: https://issues.apache.org/jira/browse/CAMEL-27354
Project: Camel
Issue Type: Bug
Components: camel-netty
Reporter: shashank
Assignee: shashank
h3. What happens
With {{reuseChannel=true}} the producer does not give the channel back when the
request is done; it adds an on-completion to the exchange that closes the
channel (if asked) and calls {{releaseChannel}} when the exchange is done. That
on-completion is a {{SynchronizationAdapter}} that only overrides
{{onComplete}}, so for a failed exchange ({{onFailure}}) nothing happens: the
channel stays borrowed for ever. This happens for a request that times out (the
channel is closed but never invalidated), for a request that fails before it is
sent (an invalid {{CamelNettyRequestTimeout}} header, for example; CAMEL-27338
leaves this case to the on-completion), and for an exchange that fails later in
the route after the reply.
Each failed exchange takes one channel of the pool for good. With
{{producerPoolMaxTotal}} set, the pool runs out after that many failures: the
next requests wait {{producerPoolMaxWait}} (by default for ever) and then fail
with {{NoSuchElementException: Timeout waiting for idle object}}. With the
default unbounded pool, the borrowed count and the open channels of failed
exchanges that were not closed keep growing.
Without {{reuseChannel}} the channel is given back by {{NettyProducerCallback}}
whatever the outcome.
h3. How to reproduce
{code:java}
from("direct:start")
.to("netty:tcp://localhost:5000?textline=true&sync=true&reuseChannel=true&producerPoolMaxTotal=1&producerPoolMaxWait=2000")
.process(e -> { throw new IllegalStateException("Forced"); });
{code}
Send one exchange (it fails as expected), then another: it fails with
{{NoSuchElementException}} after 2 seconds. The same with a request that times
out ({{requestTimeout}}), and with a request that has an invalid
{{CamelNettyRequestTimeout}} header.
Found with a TLA+ model of the producer pool with reuseChannel.
h3. Fix
The on-completion overrides {{onDone}}, which runs for a completed and for a
failed exchange. {{releaseChannel}} gives an open channel back to the pool and
invalidates a closed one, as for the other paths. Follow-up of CAMEL-27338 (a
request that fails while it is set up), which left the reuseChannel case to
this on-completion.
_Filed with Claude Code on behalf of allthingssecurity._
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)