davsclaus opened a new pull request, #29115:
URL: https://github.com/apache/camel/pull/29115

   ## Summary
   
   [CAMEL-26555](https://issues.apache.org/jira/browse/CAMEL-26555), found 
while looking at 
[CAMEL-26554](https://issues.apache.org/jira/browse/CAMEL-26554) (camel-jetty 
fix in #29114).
   
   When a graceful shutdown times out, `doShutdown` cancels its `ShutdownTask` 
(`future.cancel(true)`), then on the calling thread forces the routes to 
shutdown, aborts, or ignores the remainder routes. The cancelled task kept 
going: its wait loop ended (on the timeout flag, or on the interrupt with "will 
force shutdown now"), and it prepared and stopped the deferred consumers. So 
the same consumers were stopped by two threads at once, and the task did it on 
a thread whose interrupt flag it had just restored. A consumer whose stop waits 
on something interruptible then fails to stop. Jetty's `ManagedSelector.doStop` 
is one example, and in CAMEL-26554 that left a port that accepted no 
connections.
   
   ## Changes
   
   `DefaultShutdownStrategy.ShutdownTask`: once the timeout of its own shutdown 
occurred (the per-shutdown flag from CAMEL-26449), the task returns instead of 
preparing and stopping the deferred consumers. It checks after the wait loop 
and again before each deferred consumer. An interrupt that is not caused by the 
timeout keeps the old handling (abort or force).
   
   The calling thread still handles everything: `shutdownRoutesNow` when 
forcing, and in every case the route, route group or CamelContext stop stops 
the route services (and so the consumers) afterwards.
   
   ## Tests
   
   - New `DefaultShutdownStrategyTimeoutTaskCancelledTest`: a deferred route 
with an exchange in flight is stopped with a 1 second timeout, and a recording 
strategy notes every `shutdownNow` call with its thread. Without the fix: 
`[Camel (camel-1) thread #2 - ShutdownTask interrupted, 
ForkJoinPool-1-worker-1]`. With the fix only the calling thread stops the 
consumer.
   - camel-core: 8784 tests, 0 failures (44 skipped).
   
   _Claude Code on behalf of davsclaus_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   https://claude.ai/code/session_0128ThHB3iQdrvSRLVBGRrdP
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to