shashank created CAMEL-27212:
--------------------------------

             Summary: camel-resilience4j - Circuit Breaker EIP: in asynchronous 
mode a timeout does not fire while the calls block every thread of the pool, 
and after a route restart the calls with a timeout do not run
                 Key: CAMEL-27212
                 URL: https://issues.apache.org/jira/browse/CAMEL-27212
             Project: Camel
          Issue Type: Bug
          Components: camel-core
            Reporter: shashank
            Assignee: shashank


h3. What happens

# *Asynchronous mode* ({{asynchronous=true}}, {{timeoutEnabled=true}}): the 
reifier creates one {{ScheduledThreadPoolExecutor}} (or takes the 
{{timeoutExecutorService}}) and gives it to the processor both as the pool that 
runs the calls and as the scheduler of the {{TimeLimiter}}. The timeout of a 
call is a task of the same pool. When the calls block their threads (a 
synchronous http call to a server that does not answer, the case the timeout is 
for), and there are as many of them as threads in the pool (10 with the default 
profile), no thread is left to run the timeouts: no call times out, no fallback 
runs, the exchanges wait for as long as the server does not answer (for ever 
without a socket timeout), and the circuit breaker never records the failures, 
so it never opens. New calls queue behind them.
# *Route restart* (any mode, {{timeoutEnabled=true}}): the reifier creates the 
thread pool once, with the route, but {{ResilienceProcessor.doStop}} shuts it 
down. After {{stopRoute}} + {{startRoute}} (JMX, supervising route controller, 
CLI) the pool is terminated, and its rejection policy (CallerRuns) discards new 
tasks without an exception: in synchronous mode every call times out without 
running and goes to the fallback (or fails), and the circuit breaker opens; in 
asynchronous mode the call and its timeout are both discarded, so the exchange 
never completes and the caller waits for ever. The route does not work again 
until it is removed and added again.

h3. How to reproduce

{{ResilienceAsyncTimeoutBlockedPoolTest}}: asynchronous mode, timeout 200 ms, a 
{{timeoutExecutorService}} with one thread, a step that blocks: the fallback 
does not come within 5 seconds (it comes when the step returns).
{{ResilienceRouteRestartTest}}: after stopRoute + startRoute a circuit breaker 
with a timeout returns the fallback instead of the result of its steps 
(synchronous mode), or never answers (asynchronous mode).

h3. Fix

In asynchronous mode the processor schedules the timeouts on threads of its own 
(a scheduled thread pool created when the processor starts), and the thread 
pool runs only the calls. The thread pools are shut down when the route is 
removed ({{doShutdown}}), not when it stops, as the other EIPs with their own 
thread pool do.

_Filed with Claude Code on behalf of allthingssecurity._



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

Reply via email to