allthingssecurity opened a new pull request, #30000: URL: https://github.com/apache/camel/pull/30000
# Description [CAMEL-26951](https://issues.apache.org/jira/browse/CAMEL-26951) Follows the CAMEL-26538 PR (CAMEL-26538, the thread pool of the API components belongs to the CamelContext of the endpoint) and is built on top of it, so it contains that commit until the CAMEL-26538 PR is merged. Both change the pool lookup in `AbstractApiEndpoint`. `AbstractApiProducer.process` submits each call to the pool of its CamelContext and returns `false`; only the task calls the callback. When the pool is shut down, the default thread pool profile uses `CallerRuns`, and the JDK `CallerRunsPolicy` discards the task without running it and without an exception, so the exchange never completes. After CAMEL-26538 this can still happen in two cases: - a call that races the stop of its own CamelContext: the producer gets the pool, and the `ExecutorServiceManager` shuts it down before the `submit` (an exchange that arrives during the stop, for example from a `ProducerTemplate` or a consumer of another route that still runs); - a producer used after its CamelContext stopped: the endpoint looked up the shut down pool again and created a new one through the `ExecutorServiceManager` that was already shut down, and nothing shut that pool down until the CamelContext was started and stopped again. Change: - `AbstractApiProducer.process` fails the call at once (a `RejectedExecutionException` on the exchange, `callback.done(true)`, returns `true`) when the pool is shut down, when the lookup refuses to create a pool, or when the `submit` throws a `RejectedExecutionException` (the `Abort` policy; before, it was thrown out of `process`). - After the `submit` it checks the pool again: when the pool was shut down meanwhile, the task may have been dropped, so the call is failed. The task and this check claim the call with one `AtomicBoolean`, so the callback is called exactly once: a task that starts first runs the call, and a task that runs after the check (a pool shut down gracefully still runs its queue) does nothing. - `AbstractApiEndpoint` does not create a pool for a CamelContext that is stopping or stopped; the lookup throws a `RejectedExecutionException` instead. A pool that is there and running is still returned. One difference with the JIRA text: it also proposed to fail a call when the CamelContext is stopping. A CamelContext is stopping while its shutdown strategy waits for the in-flight exchanges, and those must still be able to call the API, so a call fails only when its pool is shut down (or would have to be created during the stop). Tests, new `AbstractApiProducerRejectedCallTest` (camel-core, the stub API component of `AbstractApiProducerTest`, a thread pool factory that creates the pools as the default one does, with the rejection policy of the profile): - `testCallRacingTheStopOfItsCamelContextFails`: the call waits between the pool lookup and the `submit` while the CamelContext stops; it then fails with a `RejectedExecutionException` and the callback is called once, instead of never; - `testCallAfterTheCamelContextStoppedFailsWithoutCreatingAPool`: a call after the stop fails at once, and no second pool is created. Without the change (on the CAMEL-26538 commit) both fail: the racing call never completes, and the call after the stop runs on a new pool instead of failing. With it they pass, and the `org.apache.camel.support` tests and the thread pool and executor service tests of camel-core pass (camel-core 706 run, 0 failures, 2 skipped; camel-support 169, camel-util 19, 0 failures). No upgrade guide entry: a call that never completed now fails with a `RejectedExecutionException`. Not covered: a task that the pool accepted and that is then dropped by a later `shutdownNow` (after this call returned) still leaves its exchange without completion. The shutdown strategy waits for the in-flight exchanges before the pools are shut down, so this needs an exchange that the strategy does not wait for. # 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-26951](https://issues.apache.org/jira/browse/CAMEL-26951). # 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 the core modules with the formatter and import-sort plugins and ran the camel-core tests named above. 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 commit carries 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]
