shashank created CAMEL-27500:
--------------------------------

             Summary: camel-core - Block rejected policy: a caller waiting for 
queue space when the thread pool is shut down puts its task into the queue of 
the dead pool
                 Key: CAMEL-27500
                 URL: https://issues.apache.org/jira/browse/CAMEL-27500
             Project: Camel
          Issue Type: Bug
          Components: camel-core
            Reporter: shashank
            Assignee: shashank


h3. What happens

The Block rejected policy ({{ThreadPoolRejectedPolicy.Block}}) checks 
{{isShutdown()}} once and then waits in {{queue.put(r)}} without a deadline, 
and does not look at the pool again once the put returns.

* {{shutdownNow}} drains the queue, which makes space, so a caller waiting in 
{{put}} is released and adds its task to the queue of a thread pool that will 
never run it. The task is neither run nor rejected. With the Threads EIP, the 
callback of that exchange is never called: when a route is removed after the 
graceful shutdown timeout (the waiting caller is an in-flight exchange, so the 
graceful shutdown waits and then removal runs {{shutdownNow}}), the consumer 
thread waits for ever. CAMEL-27088 fails the tasks that {{shutdownNow}} 
returns, but this one is added after the drain.
* with {{maxQueueSize=0}} (a {{SynchronousQueue}}), a caller waiting when the 
thread pool is shut down gracefully is never woken up: no thread takes from the 
queue any more.

h3. How to reproduce

A {{RejectableThreadPoolExecutor}} with 1 thread, queue size 1 and the Block 
policy: one task runs, one is queued, a third caller waits in {{execute}}. 
{{shutdownNow()}} returns the queued task; the third caller returns normally 
and its task is left in the queue of the terminated pool (on a Threads EIP: its 
exchange never completes).

Found with the same TLA+ model as the Threads EIP issue (a blocked caller is 
released, but into a dead queue: "callback eventually" fails), and reproduced 
with JUnit.

h3. Fix

The policy waits with {{offer}} and a timeout and looks whether the thread pool 
was shut down every 100 ms; once its task is queued it looks again, and when 
the pool was shut down meanwhile it takes the task out of the queue and rejects 
it, as {{ThreadPoolExecutor.execute}} does after it queues a task. A 
{{Rejectable}} task is rejected, any other task gets a 
{{RejectedExecutionException}}, as when the pool is already shut down. If the 
task cannot be taken out, a thread of the pool or {{shutdownNow}} has it, so it 
is completed exactly once.

_Filed with Claude Code on behalf of allthingssecurity._



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to