allthingssecurity opened a new pull request, #30920: URL: https://github.com/apache/camel/pull/30920
# Description [CAMEL-27591](https://issues.apache.org/jira/browse/CAMEL-27591) The timeout checker of a reply manager removes all expired requests from the correlation map under the map lock, then hands their timeout tasks to the on-timeout executor one by one, outside the lock (`CorrelationTimeoutMap.submitEviction`). With the default `CallerRuns` rejected policy and a full executor, a timeout task, and the rest of the routing of its exchange, runs in the checker thread. The reply manager stop waits for the checker for at most twice the `shutdownAwaitTermination` (10 seconds by default), shuts the on-timeout executor down and then completes the timeout tasks it did not run (`completePendingEvictions`, CAMEL-27321). If the checker is still routing an exchange at that point, it later hands its remaining expired requests to the shut-down executor. `CallerRuns` drops a task on a shut-down executor without an exception (it is the JDK `CallerRunsPolicy`), so the existing `RejectedExecutionException` catch does not run. The task stays in `pendingEvictions`, `done` is never called, and the exchange never completes. The fix: `submitEviction` runs the task in the calling thread when the executor is shut down after the submit, as it already does when the executor throws `RejectedExecutionException`. Running it there is what `CallerRuns` does for a full executor: the checker emits the evictions after it released the map lock, so no lock is held. The task is claimed with a CAS, so a task that the executor accepted before the shutdown (and still runs, or that the stop completes) is completed only once. The shutdown check comes after the submit: a submit accepted before the shutdown is covered by the stop, which shuts the executor down before it completes the pending tasks. camel-sjms has a copy of `CorrelationTimeoutMap` and gets the same change. camel-netty's `TimeoutCorrelationManagerSupport` already runs the task inline on a shut-down pool (CAMEL-27335), and camel-rocketmq runs its timeouts in the checker thread. It needs a mass timeout that fills the executor and an exchange whose routing in the checker thread outlasts both waits of the stop, so it is rare; when it happens a synchronous caller waits for ever. Model: found with a TLA+ model of the reply correlation (every request is completed once; with a purge slower than the stop's waits it fails on main, and holds when a task submitted to a shut-down executor runs inline). Tests: `timeoutHandedToTheExecutorAfterTheStopIsCompleted` in `ReplyManagerStopCompletesRequestsTest` of camel-jms and camel-sjms (no broker, as the other tests of the class; real `CorrelationTimeoutMap`, real `ReplyManagerSupport.doStop`, real Camel thread pools). A one-thread executor with a queue of one and `CallerRuns`, `shutdownAwaitTermination` 200 ms. Four requests time out in the same check: the first task holds the executor thread, the second is queued, the third runs in the checker thread and its routing blocks, ignoring the interrupt of the stop. The test stops the reply manager, lets the routing end, and checks that all four requests complete exactly once. On main the fourth is never completed in both modules; with the fix the test passes, also 20 times in a row, and the camel-jms and camel-sjms unit tests pass (camel-jms 577 run, camel-sjms 246 run, 0 failures, 0 errors). # Target - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch) # Tracking - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it): [CAMEL-27591](https://issues.apache.org/jira/browse/CAMEL-27591). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. (I built and tested the affected modules, including the formatter and import-sort plugins. I did not run the full root build.) # AI-assisted contributions - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used. This PR was prepared with Claude Code (Claude Opus 5.5). The commits carry a `Co-Authored-By` trailer. _Claude Code on behalf of allthingssecurity_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
