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

Memory leak from first loaded web app when log4j jars are in Tomcat's lib folder

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.1, 2.5
    • 2.5
    • Configurators, Web/Servlet
    • None
    • Tomcat 7.0.50 or Tomcat 7.0.65, jdk1.8.0_51, Win 10

    Description

      When the log4j2 jar files are in $catalina.home/lib, the first web application that is loaded will be reported by Tomcat as having a memory leak from loaded classes.

      1. Steps to reproduce

      1. Install Tomcat 7.0.65 afresh
      2. Copy log4j-api-2.5-SNAPSHOT.jar, log4j-core-2.5-SNAPSHOT.jar, log4j-web-2.5-SNAPSHOT.jar into $catalina.home/lib.
      3. (Optional) place a log4j2.xml config file with status="true" in $catalina.home/lib. This helps to confirm that the web app which is loaded first causes the warning.
      4. Edit $catalina.home/conf/catalina.properties: add log4j2.disable.jmx=true (eliminate JMX as the culprit)
      5. Edit $catalina.home/conf/tomcat-users.xml to give yourself permission to access the Tomcat Web App Manager
      6. Start Tomcat
      7. Open the Manager App
      8. Reload the Tomcat Documentation (/docs) web app
      9. Click the "Find Leaks" button under Diagnostics at the bottom of the Manager App page

      The following warning is displayed:

      The following web applications were stopped (reloaded, undeployed), but their classes from previous runs are still loaded in memory, thus causing a memory leak (use a profiler to confirm):
      /docs

      2. Use custom web app to prove the web app loaded first always has this issue
      Use the attached web app to test the order of deployment.

      1. Restart Tomcat
      2. Deploy web app (containing its own log4j2.xml)
      3. Restart Tomcat again (note that the custom web app is loaded first)
      4. Reload /docs app: no memory leak
      5. Reload /webapp: gives memory leak warning

      Different order:

      1. Undeploy custom web app
      2. Restart Tomcat ( /docs web app is loaded first)
      3. Deploy custom web app
      4. Reload /docs app: gives memory leak warning
      5. Reload /webapp: no memory leak

      I have tried to use Eclipse Memory Analyzer to find out where the leak is, but without success.

      (Note that the problem also happens with the default configuration (when no log4j2.xml config is found), this may narrow things down a little... Perhaps this has something to do with the StatusLogger?)

      Attachments

        1. webapp.war
          5 kB
          Remko Popma

        Issue Links

          Activity

            People

              rpopma Remko Popma
              rpopma Remko Popma
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: