jersey
  1. jersey
  2. JERSEY-792

Memory leak caused by application scoped thread locals are not cleaned up by Jersey

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Incomplete
    • Affects Version/s: None
    • Fix Version/s: 1.18
    • Component/s: core
    • Labels:
      None

      Description

      Originally reported at the user mailing list, see:

      http://jersey.576304.n2.nabble.com/PermGen-Memory-Leak-in-Tomcat-td6843479.html

      Quote:
      -8<-
      When the web application is undeployed Tomcat logs a warning that the application has created a ThreadLocal and not removed it:

      SEVERE: The web application [/sandbox] created a ThreadLocal with key of type [null] (value [com.sun.jersey.core.impl.provider.xml.ThreadLocalSingletonContextProvider$1@15ce9c4]) and a value of type [com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl] (value [com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl@f76983]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.

      After deploying and undeploying the app several times Tomcat runs out of PermGen space.

      ->8-

        Activity

        Hide
        mkrogh added a comment - - edited

        It would seem like this is issue not only affects the SAXParserFactory usage, I have observed it with the HttpDateFormat for headers (when you have specified a last modified date for the response).

        mar 20, 2012 10:47:48 AM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
        SEVERE: The web application [/SomeResources] created a ThreadLocal with key of type [com.sun.jersey.core.header.HttpDateFormat$1] (value
        [com.sun.jersey.core.header.HttpDateFormat$1@6fc247d5]) and a value of type [java.util.Collections.UnmodifiableRandomAccessList] (value
        [[java.text.SimpleDateFormat@c4dc9900, java.text.SimpleDateFormat@b831d961, java.text.SimpleDateFormat@937457b6]]) but failed to remove it 
        when the web application was stopped. This is very likely to create a memory leak.
        

        So it seems like an issue with ThreadLocals and tomcats thread pooling in general, see e.g. this older lucene bug: https://issues.apache.org/jira/browse/LUCENE-1383

        ( Update: ) This is observed in jersey 1.11, have not tried the 1.12 version.

        Show
        mkrogh added a comment - - edited It would seem like this is issue not only affects the SAXParserFactory usage, I have observed it with the HttpDateFormat for headers (when you have specified a last modified date for the response). mar 20, 2012 10:47:48 AM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap SEVERE: The web application [/SomeResources] created a ThreadLocal with key of type [com.sun.jersey.core.header.HttpDateFormat$1] (value [com.sun.jersey.core.header.HttpDateFormat$1@6fc247d5]) and a value of type [java.util.Collections.UnmodifiableRandomAccessList] (value [[java.text.SimpleDateFormat@c4dc9900, java.text.SimpleDateFormat@b831d961, java.text.SimpleDateFormat@937457b6]]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak. So it seems like an issue with ThreadLocals and tomcats thread pooling in general, see e.g. this older lucene bug: https://issues.apache.org/jira/browse/LUCENE-1383 ( Update: ) This is observed in jersey 1.11, have not tried the 1.12 version.
        Hide
        udachny added a comment -

        Another example, observed in Jersey 1.17. It happens while undeploying webapp.

        SEVERE: A web application created a ThreadLocal with key of type [null] (value [com.sun.xml.bind.v2.ClassFactory$1@48e8e8bf]) and a value of type [java.util.WeakHashMap] (value [{class javax.xml.bind.annotation.W3CDomHandler=java.lang.ref.WeakReference@330878fe}]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.
        
        Show
        udachny added a comment - Another example, observed in Jersey 1.17. It happens while undeploying webapp. SEVERE: A web application created a ThreadLocal with key of type [ null ] (value [com.sun.xml.bind.v2.ClassFactory$1@48e8e8bf]) and a value of type [java.util.WeakHashMap] (value [{class javax.xml.bind.annotation.W3CDomHandler=java.lang.ref.WeakReference@330878fe}]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.
        Hide
        Marek Potociar added a comment -

        We do not have enough information right now to evaluate the impact & validity of the issue. A reproducible test case would be needed. Closing as incomplete for now.

        Show
        Marek Potociar added a comment - We do not have enough information right now to evaluate the impact & validity of the issue. A reproducible test case would be needed. Closing as incomplete for now.

          People

          • Assignee:
            Unassigned
            Reporter:
            Jakub Podlesak
          • Votes:
            5 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 3 hours
              3h
              Remaining:
              Remaining Estimate - 0 minutes
              0m
              Logged:
              Time Spent - 5 minutes Time Not Required
              5m