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

Remko Popma commented on LOG4J2-1518:
-------------------------------------

Leon, I finally took a closer look at this and I see now that this is a Log4j2 
issue, not a Disruptor issue.

The 
[DefaultAsyncQueueFullPolicy|https://github.com/apache/logging-log4j2/blob/d00c38dddf6a3c90a29c14a73ba1f9e56bbbf0b9/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DefaultAsyncQueueFullPolicy.java]
 assumes that the {{toString}} method is only invoked from the background 
thread. Some changes in log4j-2.6 mean that this is no longer the case.

One way to fix this is to let DefaultAsyncQueueFullPolicy always send the event 
directly to the appender ({{return EventRoute.SYNCHRONOUS}}) unconditionally 
when the queue is full.

You don't need to wait for the next log4j2 release to address this. You can 
provide a custom policy like the below and configure log4j to use it by 
specifying system property 
{{-Dlog4j2.AsyncQueueFullPolicy=com.mypackage.MyQueueFullPolicy}}.

{code}
package com.mypackage;
public class MyQueueFullPolicy implements AsyncQueueFullPolicy {
    @Override
    public EventRoute getRoute(final long backgroundThreadId, final Level 
level) {
        return EventRoute.SYNCHRONOUS;
    }
}
{code}


> Deadlock when using pure async and toString logs another message
> ----------------------------------------------------------------
>
>                 Key: LOG4J2-1518
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1518
>             Project: Log4j 2
>          Issue Type: Bug
>    Affects Versions: 2.6.2
>         Environment: Solaris
>            Reporter: Leon Finker
>            Assignee: Remko Popma
>             Fix For: 2.7
>
>         Attachments: 10511.jstack, async_deadlock.txt
>
>
> Hi,
> It looks like this was reported before in: LOG4J2-471
> We've encountered similar issue with one of the libraries where it's toString 
> was indirectly also logging. This caused a deadlock when RingBuffer was full. 
> Please see attached stack snippet.
> According to the following docs, it's possible to set sync policy to 
> synchronously log the event if buffer is full. I don't see it documented. 
> What's the policy option?
> https://issues.apache.org/jira/plugins/servlet/mobile#issue/LOG4J2-1080
> https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/async/AsyncQueueFullPolicyFactory.html
> Thank you



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