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

Remko Popma edited comment on LOG4J2-1159 at 10/19/15 6:46 AM:
---------------------------------------------------------------

Interestingly, the sample web app does not use Async Loggers, but the memory 
leak log mentions a thread started by the AsyncLogger class and the ThreadLocal 
storing a AsyncLogger$Info instance.

The first problem: how can this happen in a web app that does not even use 
async loggers?

Answer: This seems to be caused by a change made for LOG4J2-1074, where the 
selected NanoClock is passed to the AsyncLogger class when Log4j reconfigures 
(in {{LoggerContext.setConfiguration}}). This causes static initialization 
which results in the memory leak.

I will next look at solving this issue for both the sample app and an app that 
actually uses async loggers.


was (Author: [email protected]):
Interestingly, the sample web app does not use Async Loggers, but the memory 
leak log mentions a thread started by the AsyncLogger class and the ThreadLocal 
storing a AsyncLogger$Info instance.

The first problem: how can this happen in a web app that does not even use 
async loggers?

This seems to be caused by a change made for LOG4J2-1074, where the selected 
NanoClock is passed to the AsyncLogger class when Log4j reconfigures (in 
{{LoggerContext.setConfiguration}}). This causes static initialization which 
results in the memory leak.

I will next look at solving this issue for both the sample app and an app that 
actually uses async loggers.

> ThreadLocal leaks in Tomcat8 
> (org.apache.logging.log4j.core.async.AsyncLogger.Info)
> -----------------------------------------------------------------------------------
>
>                 Key: LOG4J2-1159
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1159
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.4, 2.4.1
>            Reporter: Robin Jansohn
>            Assignee: Remko Popma
>             Fix For: 2.5
>
>
> (Regression of LOG4J2-323) 
> Since v2.4 there a TreadLocal warnings reported by Tomcat. A minimal webapp 
> to reproduce can be found here: https://github.com/jansohn/log4j2-threadlocal
> {noformat}
> WARNUNG: The web application [log4j2webapp] appears to have started a thread 
> named [AsyncLogger-1] but has failed to stop it. This is very likely to 
> create a memory leak. Stack trace of thread:
>  sun.misc.Unsafe.park(Native Method)
>  java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
>  
> java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
>  com.lmax.disruptor.BlockingWaitStrategy.waitFor(BlockingWaitStrategy.java:45)
>  
> com.lmax.disruptor.ProcessingSequenceBarrier.waitFor(ProcessingSequenceBarrier.java:55)
>  com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:123)
>  
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
>  
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
>  java.lang.Thread.run(Thread.java:745)
> Okt 14, 2015 1:06:48 PM org.apache.catalina.loader.WebappClassLoaderBase 
> checkThreadLocalMapForLeaks
> SCHWERWIEGEND: The web application [log4j2webapp] created a ThreadLocal with 
> key of type [org.apache.logging.log4j.core.async.AsyncLogger$Info$1] (value 
> [org.apache.logging.log4j.core.async.AsyncLogger$Info$1@1d29f54]) and a value 
> of type [org.apache.logging.log4j.core.async.AsyncLogger.Info] (value 
> [org.apache.logging.log4j.core.async.AsyncLogger$Info@1ea59ba]) 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.
> {noformat}



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

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to