gnodet commented on code in PR #26845:
URL: https://github.com/apache/camel/pull/26845#discussion_r4095005814


##########
components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcComponent.java:
##########
@@ -114,6 +116,56 @@ public void setConnectionStrategy(ConnectionStrategy 
connectionStrategy) {
         this.connectionStrategy = connectionStrategy;
     }
 
+    @Override
+    public void onSecretRotation(Object source) throws Exception {
+        // Collect all DataSources this component can reach: the one injected 
directly (if any)
+        // plus all DataSource beans registered in the registry. The registry 
beans are typically
+        // not recreated during a route reload, so their connection pools 
still hold connections
+        // that were authenticated with the old credentials.
+        Set<DataSource> dataSources = 
getCamelContext().getRegistry().findByType(DataSource.class);
+        if (this.dataSource != null) {
+            dataSources.add(this.dataSource);

Review Comment:
   Fixed in c30a53b6e37df954dd1a0fb1197cc9695988bc84: the orchestration is now 
in `DataSourceHelper.evictAllDataSourceConnections()` which uses 
`Collections.newSetFromMap(new IdentityHashMap<>())`. JdbcComponent and 
SqlComponent both delegate to it.



##########
components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcComponent.java:
##########
@@ -114,6 +114,23 @@ public void setConnectionStrategy(ConnectionStrategy 
connectionStrategy) {
         this.connectionStrategy = connectionStrategy;
     }
 
+    @Override
+    public void onSecretRotation(Object source) throws Exception {
+        // Use identity-based deduplication to avoid double-eviction when 
this.dataSource
+        // is the same object instance as a bean registered in the registry.
+        // (equals/hashCode on DataSource wrappers may delegate to the wrapped 
instance,
+        // causing a regular HashSet to miss duplicates or collapse distinct 
pools.)
+        Set<DataSource> dataSources = Collections.newSetFromMap(new 
IdentityHashMap<>());
+        
dataSources.addAll(getCamelContext().getRegistry().findByType(DataSource.class));
+        if (this.dataSource != null) {
+            dataSources.add(this.dataSource);
+        }
+
+        for (DataSource ds : dataSources) {
+            DataSourceHelper.evictDataSourceConnections(ds, source);
+        }
+    }

Review Comment:
   Fixed in c30a53b6e37df954dd1a0fb1197cc9695988bc84: 
`DataSourceHelper.evictAllDataSourceConnections(Registry, DataSource, Object)` 
now owns the full orchestration. `JdbcComponent.onSecretRotation()` is a 
one-liner.



-- 
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]

Reply via email to