allthingssecurity opened a new pull request, #28431: URL: https://github.com/apache/camel/pull/28431
# Description [CAMEL-25907](https://issues.apache.org/jira/browse/CAMEL-25907) The `RestClient` set with the `client` option of the Elasticsearch or OpenSearch component (the option is autowired, so a single `RestClient` bean in the registry is picked up on its own) is given to every endpoint of the component. `ElasticsearchProducer.doStop` and `OpensearchProducer.doStop` closed it, and with `disconnect=true` the cleanup after each request closed it as well. Once one route with such a producer was stopped or removed, every other endpoint of the component failed all its requests (`Request execution cancelled` for Elasticsearch, `Connection pool shut down` for OpenSearch), and so did the stopped route after it was started again, until the application was restarted. CAMEL-13763 reported this for an XML route reload in 2019; it was closed because that reload feature went away, not because the behaviour was intended. Changes: - Both producers note whether they created the client (`clientCreated`, set in `startClient`). `doStop` and the `disconnect=true` cleanup close only a client the producer created, and clear it (and the sniffer) so that a later start creates a new one. Before, a producer instance that was stopped and started again kept its closed client. - The client of the component is left to the application, as `camel-elasticsearch-rest-client` (`createdRestClient`), camel-clickhouse and camel-kudu already do. With an `openSearchClient` set, OpenSearch already left it alone; that path is unchanged. - Upgrade guide 4.24: `camel-elasticsearch, camel-opensearch - the client set on the component is not closed by Camel` (before, Camel closed it at shutdown too). Tests (new `ElasticsearchProducerClientLifecycleTest` and `OpensearchProducerClientLifecycleTest`, 4 each, using a JDK `HttpServer` that answers the ping as a node does): - `stoppingARouteKeepsTheClientOfTheComponent` (client autowired from the registry, two routes on the component, route `a` stopped, then a request on route `b`): fails on main with `CamelExecutionException` (cause `Request execution cancelled` / `Connection pool shut down`). - `disconnectKeepsTheClientOfTheComponent` (the same with `disconnect=true`, a request on `a` then one on `b`): fails on main the same way. - `stoppedProducerClosesTheClientItCreated` (producer with `hostAddresses`, stopped and started again): checks that the client it created is closed, then fails on main at the ping after the restart (the closed client is used again). - `restartedRouteCreatesANewClient` is a control: a route stop and start creates a new producer, so it passes on main too. It checks that the change keeps that working. - Unit tests with the change: camel-elasticsearch 23 run, camel-opensearch 23 run, 0 failures. How it was found: variant analysis of CAMEL-25851, CAMEL-25852 and CAMEL-25883 (a resource of the component that one endpoint closes under the others), then the JUnit tests. What was not run: the integration tests against a real Elasticsearch or OpenSearch (they need containers), and the full root build. # 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-25907](https://issues.apache.org/jira/browse/CAMEL-25907). # 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 camel-elasticsearch and camel-opensearch. No option changed. 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]
