Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-819

PermGen OutOfMemoryError when reloading webapp on Tomcat 6

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0.2
    • Fix Version/s: 2.1
    • Component/s: Core
    • Labels:
      None
    • Environment:

      Tomcat 6

      Description

      When reloading an application 3 or 4 times in Tomcat 6, the application crashes with a "java.lang.OutOfMemoryError: PermGen space" exception.

      After some investigation using the "When all else fails" section of https://wiki.apache.org/tomcat/OutOfMemory in conjunction with Java VisualVM, I have narrowed down the problem to the Thread created within org.apache.logging.log4j.core.util.CoarseCachedClock.

      When a Thread is created, it contains a reference to the classloader that it was created with. In this case, the Thread's contextClassLoader field contains a reference to the WebappClassLoader. When Tomcat attempts to unload the webapp, the Thread still holds onto this reference which prevents WebappClassLoader from being freed.

      Perhaps the Log4jServletContextListener (Log4jWebInitializerImpl) can be made to stop the CoarseCachedClock thread.

      I believe this is not an obvious issue on Tomcat 7 due to https://wiki.apache.org/tomcat/MemoryLeakProtection.

        Attachments

        1. gg-log4j2-clocks-v2.patch
          18 kB
          Gary Gregory
        2. gg-log4j2-clocks-interrupts.patch
          19 kB
          Gary Gregory
        3. demorun-tomcat6-with-reload.zip
          33 kB
          Costa Theodosiou
        4. demorun.zip
          15 kB
          Ralph Goers
        5. demo.zip
          12 kB
          Costa Theodosiou

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                costat Costa Theodosiou
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: