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/24 08:19:27 UTC

[jira] [Commented] (LOG4J2-927) Race condition between a LoggerContext stop() and async loggers

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

Remko Popma commented on LOG4J2-927:
------------------------------------

[~eschizoid] FYI: the work done in 2.4 for  LOG4J2-1120 and LOG4J2-1121 may have resolved this issue.

Also be aware that Async Loggers are being refactored for log4j 2.5 to address issues in web containers: LOG4J2-493, LOG4J2-323, LOG4J2-1172. Essentially, each log4j Configuration can now have a separate AsyncLoggerConfigHelper and associated Disruptor instance, and similarly each AsyncLoggerContext now has a separate AsyncLoggerHelper and associated Disruptor instance.
As a result, the code for AbstractConfiguration#stop() has changed a lot (and is much simpler now).

> Race condition between a LoggerContext stop() and async loggers
> ---------------------------------------------------------------
>
>                 Key: LOG4J2-927
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-927
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Appenders
>    Affects Versions: 2.1
>            Reporter: Mariano Gonzalez
>            Assignee: Remko Popma
>
> I have an application in which I'm using all async loggers. When I stop the LoggerContext, there're still some events waiting in disruptor's buffer and when it tries to execute them the context is already closed and thus those events are lost. In the case of a RollingFileAppender, I get an IOException because the outputStream has already been closed.
> As a debugging technique, I did an Appedder decorator that looks like this:
> {code:java}
> final class StopConditionSafeAppenderWrapper extends BaseAppenderWrapper
> {
>     private final LoggerContext loggerContext;
>     StopConditionSafeAppenderWrapper(Appender delegate, LoggerContext loggerContext)
>     {
>         super(delegate);
>         this.loggerContext = loggerContext;
>     }
>     @Override
>     public void append(LogEvent event)
>     {
>         if (!loggerContext.isStarted()) {
>              return;
>         }
>         super.append(event);
>     }
> }
> {code}
> With the help of a debugger, I could verify that when the append method was invoked the loggerContext was started but then by the time the exception occurred it was closed.
> It checked the code at LoggerContext#stop() and saw that there's code to prevent disruptor from taking new events once a stop() has been invoked, but there's no code to wait for the ring buffer to be fully consumed before actually stopping.



--
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