shashank created CAMEL-26045:
--------------------------------
Summary: camel-azure-cosmosdb - stopping one endpoint closes the
CosmosAsyncClient set on the component or autowired, which all endpoints share
Key: CAMEL-26045
URL: https://issues.apache.org/jira/browse/CAMEL-26045
Project: Camel
Issue Type: Bug
Components: camel-azure
Reporter: shashank
Assignee: shashank
{{CosmosDbEndpoint.doStart}} takes the {{CosmosAsyncClient}} of the
configuration (the {{cosmosAsyncClient}} option, {{@Metadata(autowired =
true)}}) or creates one, and {{doStop}} closes whichever client it has (main
9f839f4bcc9d). A client set on the component or autowired from the registry is
shared by every azure-cosmosdb endpoint, and often by the application too (for
example a Spring bean used by Spring Data Cosmos).
{{AbstractCamelContext.removeRoute}} stops the endpoints that only the removed
route used. So removing or reloading one route closes the client, and every
other azure-cosmosdb endpoint and the application fail their requests until the
application is restarted. azure-cosmos 4.75.0 {{CosmosAsyncClient.close()}}
closes its {{AsyncDocumentClient}}.
*Fix*: the endpoint remembers whether it created the client and closes only a
client it created, as azure-servicebus, eventhubs and vertexai do and as
CAMEL-25288 did for dapr. Upgrade guide (4.24): a client set on the component
or autowired is no longer closed by Camel.
*Tests*: new {{CosmosDbEndpointClientLifecycleTest}}, 2 tests.
* {{removingARouteDoesNotCloseTheSharedClient}} (a Mockito
{{CosmosAsyncClient}} in the registry, autowired into two routes; one route is
removed) fails on main: {{shared.close(); Never wanted here: ... But invoked
here: ... CosmosDbEndpoint.doStop}};
* {{anEndpointClosesTheClientItCreated}}
({{mockStatic(CosmosDbClientFactory)}}) is a control that passes on main and
with the fix: a client the endpoint created is closed on stop, and a start
after a stop creates a new one.
Unit tests of camel-azure-cosmosdb with the fix: 23 run, 0 failures.
*How it was found*: propagation of our fix pattern "stop closes a client that
came from an option/component" (CAMEL-25288, CAMEL-25276, CAMEL-25907).
*Not changed* (follow-up if wanted): {{CosmosDbConsumer}} and
{{CosmosDbProducer}} wrap the endpoint's client once, in {{doInit}}. After a
CamelContext stop and start, an endpoint that created its own client creates a
new one, while a consumer or producer that is started again keeps the closed
one.
*Affected*: main, camel-4.23.x, camel-4.22.x and camel-4.18.x (same endpoint).
Read, not run.
_Filed with Claude Code on behalf of allthingssecurity._
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)