allthingssecurity opened a new pull request, #30463:
URL: https://github.com/apache/camel/pull/30463

   # Description
   
   [CAMEL-27216](https://issues.apache.org/jira/browse/CAMEL-27216)
   
   `CassandraIdempotentRepository`, `CassandraAggregationRepository` and 
`CassandraKeyValueRepository` (and their `Named` variants) get the `CqlSession` 
to use from the application and keep it in a `CassandraSessionHolder`. The 
holder has a `managedSession` flag ("Indicates whether Session is externally 
managed"), but its only constructor sets it to `false`, so `stop()` closes the 
session and sets it to null:
   
   - the session of the application is closed when a repository stops, such as 
when its route is removed (route reload) or the CamelContext stops: the cql 
endpoints, the other repositories and the application code that use the same 
session then fail with "Session is closed";
   - the repository cannot be started again: its start prepares the statements 
on a null session (`NullPointerException`), so the route of a reload fails to 
start.
   
   Fix: the holder of a given session marks it as managed outside, so a 
repository never closes it, and the application closes it, as for any session 
it creates; upgrade guide entry in the 4.24 section. `CassandraEndpoint` uses 
the same holder for the session it creates from its `hosts`: it now says so 
with a new constructor `CassandraSessionHolder(session, managedSession)` 
(`false`), so the endpoint still closes its session when it stops, as before.
   
   Model: a small TLA+ model (`RepoRestart.tla`, KIND=cassandra: the user's 
session, another user of it, a repository stopped and started again) checks "no 
one uses a closed session". On main it is violated in 3 states (start, stop 
closes the session, start on a null session); with the change it holds.
   
   Tests: `CassandraRepositoriesSessionTest` (camel-cassandraql, mocked 
`CqlSession`, no Cassandra needed): each of the three repositories is started, 
stopped and started again; the session must not be closed, and the second start 
must work. A fourth test pins the endpoint: a cql endpoint that creates its 
session from `hosts` (the session builder is mocked) must close it when it 
stops.
   
   On main the three repository tests fail (the second start fails with a 
`NullPointerException` on the null session, after the stop closed it), and the 
endpoint test passes (the endpoint closes its session on main too). With the 
change all four pass, and the camel-cassandraql unit tests pass (12 run, 0 
failures; the ITs need a Cassandra container and were not run locally, CI runs 
them). The new class 10 times in one JVM: 40 run, 0 failures. The second commit 
adds the endpoint part: without it the endpoint test fails (the session the 
endpoint created is not closed).
   
   Not changed: `CassandraEndpoint.doStop` also closes a session that the 
endpoint looked up from the registry; that is a separate question about shared 
endpoints.
   
   # 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-27216](https://issues.apache.org/jira/browse/CAMEL-27216).
   
   # 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 touched module with the formatter and import-sort plugins; no 
option or generated file changes. 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]

Reply via email to