[
https://issues.apache.org/jira/browse/LOG4J2-1887?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15973433#comment-15973433
]
Ralph Goers edited comment on LOG4J2-1887 at 4/18/17 8:28 PM:
--------------------------------------------------------------
I don't see how the fix you are proposing works. Line 348 is in the middle of
the stop() method, so the LoggerContext is shutting down. The configuration is
set to the NullConfiguration so that when updateLoggers is called all the
loggers will be reconfigured to not be using the current configuration. Setting
the configuration to the NullConfiguraton after updateLoggers is called
accomplishes nothing and will result in errors because all the Loggers will be
pointing at the active configuration as the appenders, etc are being stopped.
Furthermore, if Mule created an appender and added it to the configuration
correctly then it should be stopped when the LoggerContext is stopped.
was (Author: [email protected]):
I don't see how the fix you are proposing works. Line 348 is in the middle of
the stop() method, so the LoggerContext is shutting down. The configuration is
set to the NullConfiguration so that when updateLoggers is called all the
loggers will be reconfigured to not be using the current configuration. Setting
the configuration to the NullConfiguraton after updateLoggers is called
accomplishes nothing and will result in errors because all the Logger will be
pointing at the configuration as the appenders, etc are being stopped.
Furthermore, if Mule created an appender and added it to the configuration
correctly then it should be stopped when the LoggerContext is stopped.
> 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)