You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Remko Popma (JIRA)" <ji...@apache.org> on 2015/10/21 13:01:27 UTC

[jira] [Comment Edited] (LOG4J2-323) ThreadLocal-leak on tomcat shutdown when using async logging

    [ https://issues.apache.org/jira/browse/LOG4J2-323?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14966241#comment-14966241 ] 

Remko Popma edited comment on LOG4J2-323 at 10/21/15 11:01 AM:
---------------------------------------------------------------

Current status (as of Log4j 2.4/2.4.1 - need to check with earlier versions):

*Web application contains the log4j configuration and jar files*
* When configuration file uses AsyncRoot/AsyncLogger: No ThreadLocal or other leaks in Tomcat.
* When making all loggers async with LoggerContextSelector system property: Tomcat warns at SEVERE level about a ThreadLocal leak (AsyncLogger$Info).

*Web container classpath contains the log4j configuration and jar files*
* When configuration file uses AsyncRoot/AsyncLogger: The first web application starts the Disruptor background thread \[AsyncLoggerConfig-1] but does not stop it until all web apps are stopped. Tomcat warns at SEVERE level that "This is very likely to create a memory leak."
* When making all loggers async with LoggerContextSelector system property: The first web application starts the Disruptor background thread \[AsyncLogger-1]. Logging works until the first web app (which can be any web app) is stopped and the Disruptor is shut down. After that logging no longer works. Log4jServletContainerInitializer and Log4jWebInitializerImpl try to start but fail to initialize a logger context.


was (Author: remkop@yahoo.com):
Current status (as of Log4j 2.4/2.4.1 - need to check with earlier versions):

* No ThreadLocal leaks in Tomcat when configuring with AsyncRoot/AsyncLogger in the configuration file.
* There _is_ a ThreadLocal leak (AsyncLogger$Info) when using the AsyncLoggerContextSelector to make all loggers async (where the WAR contains both the log4j jar files and the configuration file)

> ThreadLocal-leak on tomcat shutdown when using async logging
> ------------------------------------------------------------
>
>                 Key: LOG4J2-323
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-323
>             Project: Log4j 2
>          Issue Type: Bug
>    Affects Versions: 2.0-beta9
>         Environment: Mac OS X 10.8.4, Tomcat 7.0.42, java version 1.6.0_51
>            Reporter: Michael Kloster
>            Assignee: Remko Popma
>              Labels: Async
>             Fix For: 2.3, 2.5
>
>
> When shutting down Tomcat 7.0.42, catalina.out displays the following warning indicating a memory leak:
> {code}
> Jul 28, 2013 9:55:59 AM org.apache.coyote.AbstractProtocol start
> INFO: Starting ProtocolHandler ["http-bio-8080"]
> Jul 28, 2013 9:55:59 AM org.apache.coyote.AbstractProtocol start
> INFO: Starting ProtocolHandler ["ajp-bio-8009"]
> Jul 28, 2013 9:55:59 AM org.apache.catalina.startup.Catalina start
> INFO: Server startup in 841 ms
> Jul 28, 2013 9:56:09 AM org.apache.catalina.core.StandardServer await
> INFO: A valid shutdown command was received via the shutdown port. Stopping the Server instance.
> Jul 28, 2013 9:56:09 AM org.apache.coyote.AbstractProtocol pause
> INFO: Pausing ProtocolHandler ["http-bio-8080"]
> Jul 28, 2013 9:56:09 AM org.apache.coyote.AbstractProtocol pause
> INFO: Pausing ProtocolHandler ["ajp-bio-8009"]
> Jul 28, 2013 9:56:09 AM org.apache.catalina.core.StandardService stopInternal
> INFO: Stopping service Catalina
> Jul 28, 2013 9:56:09 AM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
> SEVERE: The web application [/asynclog] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@648bfdea]) and a value of type [org.apache.logging.log4j.core.async.AsyncLogger.Info] (value [org.apache.logging.log4j.core.async.AsyncLogger$Info@4e26d560]) 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.
> Jul 28, 2013 9:56:09 AM org.apache.coyote.AbstractProtocol stop
> INFO: Stopping ProtocolHandler ["http-bio-8080"]
> Jul 28, 2013 9:56:09 AM org.apache.coyote.AbstractProtocol stop
> INFO: Stopping ProtocolHandler ["ajp-bio-8009"]
> Jul 28, 2013 9:56:09 AM org.apache.coyote.AbstractProtocol destroy
> INFO: Destroying ProtocolHandler ["http-bio-8080"]
> Jul 28, 2013 9:56:09 AM org.apache.coyote.AbstractProtocol destroy
> INFO: Destroying ProtocolHandler ["ajp-bio-8009"]
> {code}
> {code:xml|title=log4j2.xml|borderStyle=solid}
> <?xml version="1.0" encoding="UTF-8"?>
> <configuration status="WARN">
>   <appenders>
>     <FastRollingFile name="MyFileLog" filename="logs/my.log"
>       filePattern="logs/my-%d{COMPACT}.log">
>         <PatternLayout pattern="%d %p %c{1.} [%t] %m%n" />
> 	<Policies>
> 	  <SizeBasedTriggeringPolicy size="5MB" />
> 	</Policies>
>     </FastRollingFile>
>     <Console name="Console" target="SYSTEM_OUT">
>       <PatternLayout pattern="%d %p %c{1.} [%t] %m%n" />
>     </Console>
>   </appenders>
>   <loggers>
>     <logger name="mylogger" level="INFO" additivity="false">
>       <appender-ref ref="MyFileLog" />
>     </logger>
>     <root level="TRACE">
>       <appender-ref ref="Console" />
>     </root>
>   </loggers>
> </configuration>
> {code}
> {code:title=log4j2.xml|borderStyle=solid}
> #!/bin/bash
> CATALINA_OPTS=-DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org