[ 
https://issues.apache.org/jira/browse/CASSANDRA-19457?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17834455#comment-17834455
 ] 

Bret McGuire commented on CASSANDRA-19457:
------------------------------------------

I'm attaching a couple of files that will be useful to help repro this case.

 

[^build.gradle]

[^Repro.java]

 

The Java file continually opens and closes sessions against an Astra database.  
If you monitor the number of DefaultSession instances with a profiler (visualvm 
works great for this) you should see the count of instances increase 
monotonically.  When the patch for this ticket is applied you should see this 
number decrease occasionally when GC is performed.

 

The attached Gradle file will build (and run) the repro case with all necessary 
Micrometer and MicroProfile classes in the classpath.  You can select either 
Micrometer or MicroProfile metrics via a system prop when kicking things off; 
if you don't select either option the default (Dropwizard) will be used.  
"./gradlew build" should just work.  "./gradlew run -Dmicrometer=1" or 
"./gradlew run -Dmicroprofile=1" are examples of using alternate registries for 
testing.

 

You'll also need an astra.props file containing Astra creds + SCB.  It should 
be easy enough to tweak this to use a local C* cluster if you prefer that.

> Object reference in Micrometer metrics prevent GC from reclaiming Session 
> instances
> -----------------------------------------------------------------------------------
>
>                 Key: CASSANDRA-19457
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-19457
>             Project: Cassandra
>          Issue Type: Bug
>          Components: Client/java-driver
>            Reporter: Jane He
>            Assignee: Jane He
>            Priority: Normal
>         Attachments: Repro-1.java, Repro.java, Screenshot 2024-03-06 at 
> 2.07.01 PM.png, Screenshot 2024-03-06 at 2.07.13 PM.png, build-1.gradle, 
> build.gradle
>
>          Time Spent: 2h 40m
>  Remaining Estimate: 0h
>
> There is a memory leak of previous closed {{{}DefaultSession{}}}s. It can be 
> reproduced by this:
> {code:java}
>     public static void main(String[] args) throws InterruptedException {
>         Semaphore sema = new Semaphore(20);
>         for (int i = 0; i < 10000; i++) {
>             new Thread(() -> {
>                 try {
>                     sema.acquire();
>                     try(CqlSession session = CqlSession.builder()
>                             
> .withCloudSecureConnectBundle(Paths.get("bundle.zip"))
>                             .withAuthCredentials("token", "<some token here>")
>                             .build()) {
>                         // Do stuff
>                     }
>                 } catch (Exception e) {
>                     System.out.println(e);
>                 } finally {
>                     sema.release();
>                 }
>             }).start();
>         }
>     }{code}
> On initial investigation, it seems like 
> {{MicrometerMetricUpdater.initializeGauge()}} uses 
> {{{}Gauge.{}}}{{{}_builder()_{}}} _using_ {{_Supplier_}} _._ This creates a 
> strong reference that is causing the issue.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to