allthingssecurity opened a new pull request, #29999: URL: https://github.com/apache/camel/pull/29999
# Description [CAMEL-26538](https://issues.apache.org/jira/browse/CAMEL-26538) The producers of the API components (as2, box, braintree, dhis2, fhir, google-calendar, google-drive, google-mail, google-sheets, twilio and zendesk; olingo2 and olingo4 have their own `process`) submit each call to a thread pool. `AbstractApiEndpoint` kept that pool in a static map, one per endpoint class for the whole JVM, created by the `ExecutorServiceManager` of the first CamelContext that used it. Each endpoint also kept the pool in a field and never checked it again. With two CamelContexts in one JVM, stopping the first one breaks the second one: ``` 1 context A : sends to google-drive -> creates the pool (owned by A), puts it in the static map 2 context B : sends to google-drive -> takes A's pool from the static map, keeps it in its endpoint 3 context A : stop() -> shuts the pool down (calls of B still running after the await time are interrupted) 4 context B : sends again -> submit() to the shut down pool -> CallerRuns drops the task -> the exchange never completes ``` The caller waits for good and nothing is logged (the JDK `CallerRunsPolicy` of the default profile discards a task submitted to a pool that is shut down). An endpoint object kept across a stop and start of its own CamelContext (a route built with `to(endpoint)`, or code that keeps the `Endpoint`) breaks the same way. Routes that use a URI get a new endpoint when the CamelContext starts again, so they are not affected. Change, in `AbstractApiEndpoint`: - one pool per endpoint class per CamelContext, kept in a private context plugin and created through the `ExecutorServiceManager` of that CamelContext, as before (so that CamelContext shuts it down when it stops). The lookup runs under one static lock, only on the slow path (the endpoint keeps the pool it got). The endpoint takes any `Component`, so the pools are kept on the CamelContext rather than on `AbstractApiComponent`; - the endpoint looks up the pool again when the one it kept was shut down. Tests, new `AbstractApiEndpointExecutorServiceTest` (camel-core, the stub API component of `AbstractApiProducerTest`, no external service): - `testStoppingAnotherCamelContextDoesNotStopThePool`: the second CamelContext still calls the API after the first one stopped; - `testStoppingAnotherCamelContextDoesNotInterruptItsCalls`: a call of the second CamelContext that runs while the first one stops is not interrupted; - `testEndpointKeptAcrossARestartCanStillCallTheApi`: a route built with the endpoint instance still calls the API after a restart of its CamelContext; - `testOnePoolPerCamelContextWhenFirstCallsRace`: the endpoints of two CamelContexts that look up the pool at the same time get one pool per CamelContext. Without the change all 4 fail (two calls never complete, one is interrupted, and a CamelContext gets 2 pools); 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 704 run, 0 failures, 2 skipped; camel-support 169 and camel-util 19, 0 failures). Upgrade guide (4.24): the API components use one thread pool per CamelContext, so an application with several CamelContexts can have more threads, and each pool uses the thread pool profile (such as `CamelGoogleDrive`) of its own CamelContext. Not changed: a call that races the stop of its own CamelContext (or a producer used after its CamelContext stopped) is still dropped by the shut down pool instead of failing the exchange, as on main. That is follow-up CAMEL-26951. Backport: the change cherry-picks to 4.23.x and 4.22.x (4.18.x and 4.14.x differ by a constructor); the test needs the stubs of CAMEL-26025. # 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-26538](https://issues.apache.org/jira/browse/CAMEL-26538). # 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]
