shashank created CAMEL-26951:
--------------------------------
Summary: camel-support - API components: a call refused by a shut
down thread pool is dropped instead of failing the exchange
Key: CAMEL-26951
URL: https://issues.apache.org/jira/browse/CAMEL-26951
Project: Camel
Issue Type: Bug
Components: camel-support
Reporter: shashank
Assignee: shashank
Follow-up of CAMEL-26538 (the thread pool of the API components belongs to the
CamelContext of the endpoint), found while working on it.
{{AbstractApiProducer.process}} submits each call to the pool of its
CamelContext and returns {{false}}. Only the task calls {{callback.done}}. When
the pool is shut down, the default thread pool profile uses {{CallerRuns}}, and
the JDK {{CallerRunsPolicy}} discards the task without running it and without
an exception. So the exchange never completes, and a synchronous caller waits
for good.
After CAMEL-26538, this can still happen in two cases:
* A call that races the stop of its own CamelContext: the producer gets the
pool, and the CamelContext's ExecutorServiceManager shuts it down before the
{{submit}}. The shutdown strategy waits for in-flight exchanges first, so this
needs an exchange that arrives during the stop, for example from a
{{ProducerTemplate}} or a consumer of another route that is still running.
* A producer used after its CamelContext stopped: the endpoint creates a new
pool through the ExecutorServiceManager, which is already shut down. Nothing
shuts that pool down until that CamelContext is started and stopped again, so
its threads stay until then. The same happens on main.
*Proposal*
* Fail fast in {{AbstractApiProducer.process}}: when the pool is shut down (or
the CamelContext is stopping), set a {{RejectedExecutionException}} on the
exchange, call {{callback.done(true)}} and return {{true}}. This leaves only a
tiny window. Closing it fully needs a check after the {{submit}} with an
exactly-once guard against the task. {{Rejectable}} alone is not enough,
because the default {{CallerRuns}} handler discards the task without calling it.
* Do not create a pool for a CamelContext that is stopping or stopped; fail the
call instead.
* Test: hold a call between the pool lookup and the {{submit}} while the
CamelContext stops, and expect the exchange to fail instead of hanging.
_Filed with Claude Code on behalf of allthingssecurity._
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)