Log4j 2
  1. Log4j 2
  2. LOG4J2-425

Permgen leak in AsyncLoggerConfigHelper

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-beta9
    • Fix Version/s: 2.0-rc1
    • Component/s: Appenders
    • Labels:
      None
    • Environment:

      JDK7, Win8 64bit

      Description

      Thread local 'currentLogEvent' is not cleaned on shutdown which prevent web applications clean undeploying.
      Tomcat prints following:

      SEVERE: The web application [/web] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@22410487]) and a value of type [org.apache.logging.log4j.core.impl.Log4jLogEvent] (value [Logger=********* Level=INFO Message=************]) 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.
      

      We use async loggers declared explicitly in log4j2.xml:
      <AsyncLogger name="logger" additivity="false" level="trace"> ......

      We use RollingRandomAccessFile as appender.

        Issue Links

          Activity

          Sergey Alaev created issue -
          Remko Popma made changes -
          Field Original Value New Value
          Description Thread local 'currentLogEvent' is not cleaned on shutdown which prevent web applications clean undeploying.
          Tomcat prints following:
          SEVERE: The web application [/web] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@22410487]) and a value of type [org.apache.logging.log4j.core.impl.Log4jLogEvent] (value [Logger=********* Level=INFO Message=************]) 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.

          We use async loggers declared explicitly in log4j2.xml:
          <AsyncLogger name="logger" additivity="false" level="trace"> ......

          We use RollingRandomAccessFile as appender.


          Thread local 'currentLogEvent' is not cleaned on shutdown which prevent web applications clean undeploying.
          Tomcat prints following:
          {code}
          SEVERE: The web application [/web] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@22410487]) and a value of type [org.apache.logging.log4j.core.impl.Log4jLogEvent] (value [Logger=********* Level=INFO Message=************]) 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.
          {code}

          We use async loggers declared explicitly in log4j2.xml:
          <AsyncLogger name="logger" additivity="false" level="trace"> ......

          We use RollingRandomAccessFile as appender.


          Remko Popma made changes -
          Link This issue duplicates LOG4J2-323 [ LOG4J2-323 ]
          Hide
          Remko Popma added a comment -

          To be exact, this issue is not exactly a duplicate of LOG4J2-323, because it happens with AsyncLoggerConfigHelper (mixed async and sync loggers) and the issue reported in LOG4J2-323 happens with AsyncLogger (all loggers are async).

          However, the underlying cause is the same, and they should be fixed together. I'll add a note to LOG4J2-323 to link to this issue.

          I will also link both issues to LOG4J2-406, as any work to release the ThreadLocal references should be done at the same timing as unregistering MBeans.

          Show
          Remko Popma added a comment - To be exact, this issue is not exactly a duplicate of LOG4J2-323 , because it happens with AsyncLoggerConfigHelper (mixed async and sync loggers) and the issue reported in LOG4J2-323 happens with AsyncLogger (all loggers are async). However, the underlying cause is the same, and they should be fixed together. I'll add a note to LOG4J2-323 to link to this issue. I will also link both issues to LOG4J2-406 , as any work to release the ThreadLocal references should be done at the same timing as unregistering MBeans.
          Remko Popma made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Resolution Duplicate [ 3 ]
          Remko Popma made changes -
          Resolution Duplicate [ 3 ]
          Status Resolved [ 5 ] Reopened [ 4 ]
          Assignee Remko Popma [ remkop@yahoo.com ]
          Hide
          Remko Popma added a comment -

          Eliminated ThreadLocal from AsyncLoggerConfigHelper by using EventTranslatorTwoArg (essentially passing the log event via the call stack instead of via a field).

          Fixed in revision 1532427.
          Please verify and close.

          Show
          Remko Popma added a comment - Eliminated ThreadLocal from AsyncLoggerConfigHelper by using EventTranslatorTwoArg (essentially passing the log event via the call stack instead of via a field). Fixed in revision 1532427. Please verify and close.
          Remko Popma made changes -
          Status Reopened [ 4 ] Resolved [ 5 ]
          Fix Version/s 2.0-rc1 [ 12325011 ]
          Resolution Fixed [ 1 ]

            People

            • Assignee:
              Remko Popma
              Reporter:
              Sergey Alaev
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development