shashank created CAMEL-27499:
--------------------------------
Summary: camel-core - Threads EIP: an exchange handed to a thread
pool that is shut down is dropped, and its caller waits for ever
Key: CAMEL-27499
URL: https://issues.apache.org/jira/browse/CAMEL-27499
Project: Camel
Issue Type: Bug
Components: camel-core
Reporter: shashank
Assignee: shashank
h3. What happens
The Threads EIP hands the exchange to its thread pool
({{executorService.submit}}) and returns false, so the routing engine waits for
the task to call the callback. With the CallerRuns rejected policy (the default
of the default thread pool profile), a thread pool that is shut down does not
run a new task and does not throw either:
{{ThreadPoolExecutor.CallerRunsPolicy}} does nothing when the pool is shut
down, and {{submit}} returns normally. The exchange is then never completed:
the caller (a {{ProducerTemplate}} request, a consumer thread waiting in the
async processor await manager) waits for ever, the exchange stays in the
in-flight registry, and a graceful shutdown waits its full timeout for it.
Nothing is logged and no exception is set.
Three ways to get there:
* {{threads().executorService("sharedPool")}} with a thread pool that the route
does not own, which its owner shuts down: every later exchange hangs.
* the route is removed (after the graceful shutdown timeout) while an exchange
is between the EIP's running check and the submit: the EIP's own pool is shut
down meanwhile.
* a thread pool of the user from {{java.util.concurrent.Executors}}: its
AbortPolicy throws, {{handleException}} then applies the EIP's own CallerRuns
policy on the shut down pool, which drops that call too, and {{process}}
returns true without calling the callback.
h3. How to reproduce
{{from("direct:start").threads().executorService("sharedPool").to("mock:result")}}
with {{sharedPool}} from {{newDefaultThreadPool}}; call
{{sharedPool.shutdown()}}, then {{template.asyncSend("direct:start",
...).get(10, SECONDS)}} times out (the exchange stays in flight).
Found with a TLA+ model of the Threads and Wire Tap EIPs with each rejected
policy, racing with route stop, removal and the shutdown of a shared pool
("every exchange handed to the EIP has its callback called exactly once" fails
for CallerRuns), and reproduced with JUnit.
h3. Fix
As CAMEL-26951 did for the API components and CAMEL-27088 for the Delay EIP:
after the submit (and after the EIP's own policy in {{handleException}}), when
the thread pool is shut down, the exchange is failed in the calling thread with
a {{RejectedExecutionException}} ({{RouteStoppingException}} when the EIP is
stopped). The task, a reject and this check claim the exchange once, so the
callback is called exactly once: a task that was still queued in a gracefully
shut down pool does not complete the exchange a second time.
_Filed with Claude Code on behalf of allthingssecurity._
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)