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

Ralph Goers edited comment on LOG4J2-1887 at 4/18/17 8:53 PM:
--------------------------------------------------------------

Hi [[email protected]]. 
Mule creates an Appender in updateLoggers() if It doesn't exist in 
configuration.
When LoggerContext is stopped, and configuration is set to NullConfiguration, 
the appender is added by Mule to NullConfiguration (because Mule Code doesn't 
find an Appender in NullConfiguration), but the code in LoggerContext stop(), 
stop the previous (original) configuration and not the NullConfiguration.

{code}
final Configuration prev = configuration;
            updateLoggers();
            if (prev instanceof LifeCycle2) {
                ((LifeCycle2) prev).stop(timeout, timeUnit);   // It is the 
line where only previous configuration is stopped.
            } else {
                prev.stop(); 
            }
{code}

I could check in the Mule Code if the configuration of the LoggerContext is a 
NullConfiguration before create an appender, but I amn't sure if It would be a 
hack, because It's an internal behaviour of Log4J. 
I think Mule is adding the Appender as expected, because Mule code doesn't know 
that the configuration was changed to NullConfiguration because the 
LoggerContext was stopped.


was (Author: facundovs):
Hi [[email protected]]. 
Mule creates an Appender in updateLoggers() if It doesn't exist in 
configuration.
When LoggerContext is stopped, and configuration is set to NullConfiguration, 
the appender is added by Mule to NullConfiguration (because Mule Code doesn't 
find an Appender in NullConfiguration), but the code in LoggerContext stop(), 
stop the previous (original) configuration and not the NullConfiguration.

final Configuration prev = configuration;
            updateLoggers();
            if (prev instanceof LifeCycle2) {
                ((LifeCycle2) prev).stop(timeout, timeUnit);   // It is the 
line where only previous configuration is stopped.
            } else {
                prev.stop(); 
            }

I could check in the Mule Code if the configuration of the LoggerContext is a 
NullConfiguration before create an appender, but I amn't sure if It would be a 
hack, because It's an internal behaviour of Log4J. 
I think Mule is adding the Appender as expected, because Mule code doesn't know 
that the configuration was changed to NullConfiguration because the 
LoggerContext was 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)

Reply via email to