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

Sascha Scholz commented on LOG4J2-1235:
---------------------------------------

I think I've found another race condition that is related to how appenders are 
purged: In update(), appenders are put into the appendersUsage map with its 
current usage time. In purge(), they are removed again if timeToLive has 
expired, then the appender is deleted. So, we have three different execution 
orders when update() and purge() run concurrently.


{noformat}
appendersUsage.remove()
routingAppender.delete()
appendersUsage.put()
{noformat}
This is ok. Appender is removed and deleted, and then added again. Appender is 
only removed after put when next timeToLive expired.


{noformat}
appendersUsage.put()
appendersUsage.remove()
routingAppender.delete()
{noformat}
This is not optimal. The just added appender is removed and deleted, althouth 
timeToLive is extended. This could be solved by using remove(entry.getKey(), 
entry.getValue()) and then deleting the appender only on successful removal.


{noformat}
appendersUsage.remove()
appendersUsage.put()
routingAppender.delete()
{noformat}
This is the worst case. The appender is removed from the map, but immediately 
added back. Afterwards the appender is deleted. On the next run of purge() 
deletion will be re-attempted, which leads to a NPE in 
RoutingAppender#deleteAppender because there appender.remove() returns null for 
the already deleted appender.

Should I open this as a separate bug or should it be treated here?

> org.apache.logging.log4j.core.appender.routing.IdlePurgePolicy not working 
> correctly
> ------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-1235
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1235
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Appenders
>    Affects Versions: 2.5
>            Reporter: Niranjan Rao
>            Priority: Critical
>
> There is a problem in the function 
> org.apache.logging.log4j.core.appender.routing.IdlePurgePolicy.scheduleNext().
> I got out of file handles errors despite of setting IdlePurgePolicy. I did 
> some digging I believe following is the cause
> If the createTime is Long.MAX_VALUE, task is never scheduled. However 
> function 
> org.apache.logging.log4j.core.appender.routing.IdlePurgePolicy.update(String, 
> LogEvent) checks if the future is not null before deciding to schedule.
> After appendersUsage becomes empty first time, appenders keep piling up.
> I believe fix will be to set future to null in the function scheduleNext in 
> the else part of the condition where it checks for createTime



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