Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-130

Memory Leaks with ThreadLocals in Tomcat

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.2
    • Component/s: None
    • Labels:
      None
    • Environment:
      Fedora, Tomcat
    • Operating System:
      ALL
    • # Replies:
      31
    • Last comment by Customer:
      true

      Description

      When running mongo 2.0 in a tomcat environment I can see the following logs in the catalina.out, and the tomcat web server can't be stopped any more without killing it, it seems that there's a non-deamon thread still hanging.

      SEVERE: A web application created a ThreadLocal with key of type [null] (value [com.mongodb.DBTCPConnector$1@d5ba1ef]) and a value of type [com.mongodb.DBTCPConnector.MyPort] (value [com.mongodb.DBTCPConnector$MyPort@7ae458c2]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.
      Jul 8, 2010 7:28:23 AM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
      SEVERE: A web application created a ThreadLocal with key of type [null] (value [com.mongodb.OutMessage$1@257f6796]) and a value of type [com.mongodb.OutMessage] (value [com.mongodb.OutMessage@4f69bc15]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.
      Jul 8, 2010 7:28:23 AM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
      SEVERE: A web application created a ThreadLocal with key of type [null] (value [com.mongodb.Response$1@26bb2f6e]) and a value of type [org.bson.BSONDecoder] (value [org.bson.BSONDecoder@4b26f29f]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.

      1. threadlocal1.patch
        2 kB
        Hans Meiser

        Activity

        Hide
        daspilker Daniel Spilker added a comment -

        I tried the 2.2 driver today. Unfortunately this issue seems not to be fixed. I still count 3 thread locals (2 in org.bson.BSON and 1 in com.mongodb.DBTCPConnector). I do not see why these should get GC'ed when Mongo.close() is called, since the contents of the thread locals will still be referenced from each thread which used these classes. It will get GC'ed when the threads die, but in a shared environment like servlet containers where threads are pooled and reused this is not going to happen.

        Show
        daspilker Daniel Spilker added a comment - I tried the 2.2 driver today. Unfortunately this issue seems not to be fixed. I still count 3 thread locals (2 in org.bson.BSON and 1 in com.mongodb.DBTCPConnector). I do not see why these should get GC'ed when Mongo.close() is called, since the contents of the thread locals will still be referenced from each thread which used these classes. It will get GC'ed when the threads die, but in a shared environment like servlet containers where threads are pooled and reused this is not going to happen.
        Hide
        eliot Eliot Horowitz added a comment -

        The 2 in org.bson should never be using by normal operations, and accoring to tomcat docs, it seems the other should be.
        If you see issues in an app - please open a new ticket with the exact errors

        Show
        eliot Eliot Horowitz added a comment - The 2 in org.bson should never be using by normal operations, and accoring to tomcat docs, it seems the other should be. If you see issues in an app - please open a new ticket with the exact errors
        Hide
        klu2 Klaus Lehner added a comment -

        This is still the case, even with 2.3.

        I still have errors like that in my catalina.out and tomcat can't be stopped without killing it. Please reopen that task.

        SEVERE: A web application created a ThreadLocal with key of type [null] (value [com.mongodb.DBTCPConnector$1@4b6eb12]) and a value of type [com.mongodb.DBTCPConnector.MyPort] (value [com.mongodb.DBTCPConnector$MyPort@6fe23ecd]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.

        Show
        klu2 Klaus Lehner added a comment - This is still the case, even with 2.3. I still have errors like that in my catalina.out and tomcat can't be stopped without killing it. Please reopen that task. SEVERE: A web application created a ThreadLocal with key of type [null] (value [com.mongodb.DBTCPConnector$1@4b6eb12] ) and a value of type [com.mongodb.DBTCPConnector.MyPort] (value [com.mongodb.DBTCPConnector$MyPort@6fe23ecd] ) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.
        Hide
        eliot Eliot Horowitz added a comment -

        Can you create a new case with the full log and steps to reproduce exactly?

        Show
        eliot Eliot Horowitz added a comment - Can you create a new case with the full log and steps to reproduce exactly?
        Hide
        klu2 Klaus Lehner added a comment -

        ah sorry - forgot to call close() as mentioned by eliot; will give that a try

        Show
        klu2 Klaus Lehner added a comment - ah sorry - forgot to call close() as mentioned by eliot; will give that a try

          People

          • Votes:
            4 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since reply:
              4 years, 24 weeks, 6 days ago
              Date of 1st Reply: