[
https://issues.apache.org/jira/browse/LOG4J2-1887?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15973522#comment-15973522
]
Gary Gregory commented on LOG4J2-1887:
--------------------------------------
Having NullConfiguration immutable from the start would derailed this approach
from day 0. "What could that possibly break?" he wondered...
> A FileDescriptor that points to a log file is never closed.
> -----------------------------------------------------------
>
> Key: LOG4J2-1887
> URL: https://issues.apache.org/jira/browse/LOG4J2-1887
> Project: Log4j 2
> Issue Type: Bug
> Components: Core
> Affects Versions: 2.8.1
> Reporter: Facundo Velazquez
>
> Using Log4J, I have found that some files aren't released after the logger
> context was closed.
> Profiling the application I could find a open FileOutputStream was retained
> by the RoolingFileManager.
> Debugging I could find that this part of the code is causing the bug:
> In org.apache.logging.log4j.core.LoggerContext, line 348
> (https://github.com/apache/logging-log4j2/blob/master/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java#L348),
> the configuration of the loggerContext is set to NULL_CONFIGURATION before
> call updateLoggers(); method.
> Currently, MuleESB is using the updateLoggers method to create a FileAppender
> if It doesn't exist:
> if (!hasFileAppender(context))
> {
> addDefaultAppender(context, logFile.getAbsolutePath());
> removeConsoleAppender(context);
> }
> Due to the configuration isn't the original, It doesn't have a FileAppender,
> so Mule creates a new Appender and adds it to the NULL_CONFIGURATION.
> When a new Appender is created, a count in Manager is incremented. (You can
> see it here:
> https://github.com/apache/logging-log4j2/blob/master/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractManager.java#L121).
> Then, when the LoggerContext is closed, the FileOutputStream which is
> pointing to the log file, only is closed if the count of the appenders is
> zero. (You can see in:
> https://github.com/apache/logging-log4j2/blob/master/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractManager.java#L82).
> However, in this case, It will never be zero, because there is an appender
> which never be released, because It was added to the NULL_CONFIGURATION.
> It could be easilly fixed, putting the following line:
> configuration = NULL_CONFIGURATION;
> in the finally block, after the updateLoggers() call.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)