[logback-dev] [JIRA] (LOGBACK-1469) AsycAppender defined in configuration but not used in any logger is not stopping by shutdown hook

QOS.CH (JIRA) noreply-jira at qos.ch
Fri Jun 14 17:19:00 CEST 2019


Alexandr Bolbat created LOGBACK-1469:
----------------------------------------

             Summary: AsycAppender defined in configuration but not used in any logger is not stopping by shutdown hook
                 Key: LOGBACK-1469
                 URL: https://jira.qos.ch/browse/LOGBACK-1469
             Project: logback
          Issue Type: Improvement
          Components: logback-classic, logback-core
    Affects Versions: 1.2.3
         Environment: Any environment
            Reporter: Alexandr Bolbat
            Assignee: Logback dev list
            Priority: Critical


If we define 3 async appenders:

 
{code:java}
<appender name="ConsoleInfoAppenderAsync" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>5000</queueSize>
<discardingThreshold>0</discardingThreshold>
<appender-ref ref="ConsoleInfoAppender" />
<includeCallerData>true</includeCallerData>
</appender>

<appender name="ConsoleDebugAppenderAsync" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>5000</queueSize>
<discardingThreshold>0</discardingThreshold>
<appender-ref ref="ConsoleDebugAppender" />
<includeCallerData>true</includeCallerData>
</appender>

<appender name="ConsoleTraceAppenderAsync" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>5000</queueSize>
<discardingThreshold>0</discardingThreshold>
<appender-ref ref="ConsoleTraceAppender" />
<includeCallerData>true</includeCallerData>
</appender>

...{code}
Then define loggers:

 

 
{code:java}
<logger name="some.package" level="DEBUG" additivity="true">
<appender-ref ref="ConsoleDebugAppenderAsync" />
<appender-ref ref="ConsoleInfoAppenderAsync" />
</logger>

<root level="INFO">
<appender-ref ref="ConsoleInfoAppenderAsync" />
</root>
{code}
And shutdown hook:

 

 
{code:java}
<shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook" />
{code}
 

On application shutdown we will have executed stop for 2 appenders:
{code:java}
ConsoleDebugAppenderAsync
ConsoleInfoAppenderAsync
{code}
And related threads would be stopped.

 

But shutdown for third appender will be ignored (or just not executed):
{code:java}
ConsoleTraceAppenderAsync
{code}
In result their thread will exist and still working:
{code:java}
AsyncAppender-Worker-ConsoleTraceAppenderAsync
{code}
 

In case of web application deployed to tomcat we will see warning about this:
{code:java}
14-Jun-2019 18:03:43.568 WARNING [Thread-19] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [ROOT] appears to have started a thread named [AsyncAppender-Worker-ConsoleTraceAppenderAsync] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.base at 11/jdk.internal.misc.Unsafe.park(Native Method)
java.base at 11/java.util.concurrent.locks.LockSupport.park(LockSupport.java:194)
java.base at 11/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2081)
java.base at 11/java.util.concurrent.ArrayBlockingQueue.take(ArrayBlockingQueue.java:417)
ch.qos.logback.core.AsyncAppenderBase$Worker.run(AsyncAppenderBase.java:289)
{code}
 

Would be nice to improve graceful shutdown process for this case.

 

 



--
This message was sent by Atlassian JIRA
(v7.3.1#73012)


More information about the logback-dev mailing list