Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-4058

ContainerHolder causes ThreadLocal memory leak

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.14
    • 2.3.15
    • Core Actions
    • None
    • Tomcat 7.0.39
      java version "1.7.0_15"
      OpenJDK Runtime Environment (IcedTea7 2.3.7) (7u15-2.3.7-0ubuntu1~12.04.1)
      OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

    Description

      The localContext ThreadLocal is not cleaned up properly when stopping / undeploying / redeploying a S2 application. This will in most cases cause the web application ClassLoader not to be garbage collected, thus leaving a redeployment memory leak.

      I am using Tomcat 7.0.39 and when I undeploy my application the following is reported in the logs:

      2013-04-23 12:00:31,082 [request-worker-4] ERROR org.apache.catalina.loader.WebappClassLoader- The web application [/dev] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@7f2283e1]) and a value of type [com.opensymphony.xwork2.inject.ContainerImpl] (value [com.opensymphony.xwork2.inject.ContainerImpl@330069fc]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
      2013-04-23 12:00:31,083 [request-worker-4] ERROR org.apache.catalina.loader.WebappClassLoader- The web application [/dev] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@7f2283e1]) and a value of type [com.opensymphony.xwork2.inject.ContainerImpl] (value [com.opensymphony.xwork2.inject.ContainerImpl@330069fc]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
      2013-04-23 12:00:31,101 [request-worker-4] ERROR org.apache.catalina.loader.WebappClassLoader- The web application [/dev] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@7f2283e1]) and a value of type [com.opensymphony.xwork2.inject.ContainerImpl] (value [com.opensymphony.xwork2.inject.ContainerImpl@330069fc]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
      2013-04-23 12:00:31,101 [request-worker-4] ERROR org.apache.catalina.loader.WebappClassLoader- The web application [/dev] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@7f2283e1]) and a value of type [com.opensymphony.xwork2.inject.ContainerImpl] (value [com.opensymphony.xwork2.inject.ContainerImpl@330069fc]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
      2013-04-23 12:00:31,101 [request-worker-4] ERROR org.apache.catalina.loader.WebappClassLoader- The web application [/dev] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@7f2283e1]) and a value of type [com.opensymphony.xwork2.inject.ContainerImpl] (value [com.opensymphony.xwork2.inject.ContainerImpl@330069fc]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
      2013-04-23 12:00:31,101 [request-worker-4] ERROR org.apache.catalina.loader.WebappClassLoader- The web application [/dev] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@7f2283e1]) and a value of type [com.opensymphony.xwork2.inject.ContainerImpl] (value [com.opensymphony.xwork2.inject.ContainerImpl@330069fc]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
      2013-04-23 12:00:31,102 [request-worker-4] ERROR org.apache.catalina.loader.WebappClassLoader- The web application [/dev] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@7f2283e1]) and a value of type [com.opensymphony.xwork2.inject.ContainerImpl] (value [com.opensymphony.xwork2.inject.ContainerImpl@330069fc]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
      2013-04-23 12:00:31,102 [request-worker-4] ERROR org.apache.catalina.loader.WebappClassLoader- The web application [/dev] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@7f2283e1]) and a value of type [com.opensymphony.xwork2.inject.ContainerImpl] (value [com.opensymphony.xwork2.inject.ContainerImpl@330069fc]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
      2013-04-23 12:00:31,103 [request-worker-4] ERROR org.apache.catalina.loader.WebappClassLoader- The web application [/dev] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@7f2283e1]) and a value of type [com.opensymphony.xwork2.inject.ContainerImpl] (value [com.opensymphony.xwork2.inject.ContainerImpl@330069fc]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
      2013-04-23 12:00:31,103 [request-worker-4] ERROR org.apache.catalina.loader.WebappClassLoader- The web application [/dev] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@7f2283e1]) and a value of type [com.opensymphony.xwork2.inject.ContainerImpl] (value [com.opensymphony.xwork2.inject.ContainerImpl@330069fc]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
      2013-04-23 12:00:31,103 [request-worker-4] ERROR org.apache.catalina.loader.WebappClassLoader- The web application [/dev] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@7f2283e1]) and a value of type [com.opensymphony.xwork2.inject.ContainerImpl] (value [com.opensymphony.xwork2.inject.ContainerImpl@330069fc]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
      2013-04-23 12:00:31,103 [request-worker-4] ERROR org.apache.catalina.loader.WebappClassLoader- The web application [/dev] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@7f2283e1]) and a value of type [com.opensymphony.xwork2.inject.ContainerImpl] (value [com.opensymphony.xwork2.inject.ContainerImpl@330069fc]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
      

      After poking around in the heap dump it would seem that Tomcat is correct. There is indeed a GC root at the ThreadLocal used by the ContainerImpl.

      Attachments

        1. hprof.png
          116 kB
          Boris Morris
        2. hprof_2.png
          121 kB
          Boris Morris

        Issue Links

          Activity

            People

              lukaszlenart Lukasz Lenart
              bmorris591 Boris Morris
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: