Uploaded image for project: 'Cassandra'
  1. Cassandra
  2. CASSANDRA-19457

Object reference in Micrometer metrics prevent GC from reclaiming Session instances

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Normal
    • Resolution: Fixed
    • None
    • Client/java-driver
    • None
    • All
    • None

    Description

      There is a memory leak of previous closed DefaultSessions. It can be reproduced by this:

          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();
              }
          }

      On initial investigation, it seems like MicrometerMetricUpdater.initializeGauge() uses Gauge.builder() using Supplier . This creates a strong reference that is causing the issue.

      Attachments

        1. build.gradle
          1 kB
          Bret McGuire
        2. build-1.gradle
          2 kB
          Bret McGuire
        3. Repro.java
          3 kB
          Bret McGuire
        4. Repro-1.java
          3 kB
          Bret McGuire
        5. Screenshot 2024-03-06 at 2.07.01 PM.png
          88 kB
          Jane He
        6. Screenshot 2024-03-06 at 2.07.13 PM.png
          154 kB
          Jane He

        Issue Links

          Activity

            People

              janesiyaohe Jane He
              janesiyaohe Jane He
              Jane He
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 4.5h
                  4.5h