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 "Ralph Goers (JIRA)" <ji...@apache.org> on 2014/07/07 08:50:33 UTC

[jira] [Comment Edited] (LOG4J2-702) LoggerConfig#waitForCompletion is not thread safe

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

Ralph Goers edited comment on LOG4J2-702 at 7/7/14 6:50 AM:
------------------------------------------------------------

First, I have to assume the problem description is incorrect and that all references to LoggerContext should be LoggerConfig?

Second, the clearAppenders method is called by stop (and really shouldn't be called by anything else).  The stop method should only be called after updateLoggers has been called to transfer logging to a new configuration, in which case calls to all log events would go there, not to the configuration being stopped, or during a shutdown, at which point logging shouldn't be happening.

Do you have a stack trace that shows an actual problem or is this a hypothetical exercise?


was (Author: ralph.goers@dslextreme.com):
First, I have to assume the problem description is incorrect and that all references to LoggerContext should be LoggerConfig?

Second, the clearAppenders method is called by stop (and really shouldn't be called by anything else).  The stop method should only be called after updateLoggers has been called to transfer logging to a new configuration, in which calls all logging events would go there, not to the current configuration or during a shutdown, at which point logging shouldn't be happening.

Do you have a stack trace that shows an actual problem or is this a hypothetical exercise?

> LoggerConfig#waitForCompletion is not thread safe
> -------------------------------------------------
>
>                 Key: LOG4J2-702
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-702
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.0-rc2
>            Reporter: Sean Bridges
>            Assignee: Matt Sicker
>            Priority: Critical
>             Fix For: 2.0
>
>
> This is in trunk, svn commit 1608156
> LoggerConfig#waitForCompletion uses an AtomicInteger counter to try to detect if there are any calls currently executing the log(Event) method, but it does not do so in a thread safe manner.  Consider two threads A and B, where Thread A is calling clearAppenders(), and Thread B is calling log(Event),
> {code}
> Thread A  loggerConfig.clearAppenders()
> Thread A  loggerConfig.waitForCompletion()
> Thread A  counter.get() //returns 0
> Thread A  //loggerConfig.waitForCompletion() returns
> Thread B  loggerConfig.log(Event)
> Thread B  counter.increment()
> Thread A  proceeds assuming no log calls are onging, but thread B is in the log method
> {code}
> I'm not sure what the requirements are, but if the requirement is to not lose logging events, I think you need some sort of synchronization outside of the LoggerConfig object.  



--
This message was sent by Atlassian JIRA
(v6.2#6252)

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