allthingssecurity commented on code in PR #30463:
URL: https://github.com/apache/camel/pull/30463#discussion_r4639878793


##########
components/camel-cassandraql/src/main/java/org/apache/camel/component/cassandra/CassandraEndpoint.java:
##########
@@ -170,20 +172,31 @@ protected void doStart() throws Exception {
             }
         }
 
+        createdSession = false;
         if (session == null && hosts != null) {
             // use the session builder to create the cluster
             session = createSessionBuilder().build();
+            createdSession = true;
         }
 
-        sessionHolder = new CassandraSessionHolder(session);
+        // the endpoint closes only the session it created from its hosts; a 
session it was given (session) or looked
+        // up (beanRef) is managed outside, and other endpoints, repositories 
or the application can use it
+        sessionHolder = new CassandraSessionHolder(session, !createdSession);
 
         sessionHolder.start();
     }
 
     @Override
     protected void doStop() throws Exception {
         super.doStop();
-        sessionHolder.stop();
+        if (sessionHolder != null) {

Review Comment:
   Thanks for checking this path. I don't think it can happen with the code as 
it is on the head (25584d33b90a): in `doStart` the only statements between 
`session = createSessionBuilder().build()` and `sessionHolder = new 
CassandraSessionHolder(session, !createdSession)` are `createdSession = true` 
and that constructor, which only assigns its two fields. 
`sessionHolder.start()` after it is empty. So when `createdSession` is true, 
`sessionHolder` always holds that same session with `managedSession = false`, 
and `doStop` closes it through `sessionHolder.stop()` before it sets `session` 
to null. If `build()` itself throws, `createdSession` stays false and there is 
no session to close.
   
   A failing start after the build cannot be set up in a test without changing 
the endpoint, so I left the code as it is, as #30463 is already approved. If 
you prefer the extra branch as a guard against future changes to `doStart`, I 
can add it.
   
   _Claude Code on behalf of allthingssecurity_
   



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