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

Matthias Hess edited comment on LOG4NET-501 at 1/11/18 8:54 PM:
----------------------------------------------------------------

Hi, I guess my point was this:
{quote}The finalizers of two objects are not guaranteed to run in any specific 
order, even if one object refers to the other. That is, if Object A has a 
reference to Object B and both have finalizers, Object B might have already 
been finalized when the finalizer of Object A starts.
{quote}
taken from https://msdn.microsoft.com/en-us/library/system.object.finalize.aspx

I can't remember this issue exactly and I haven't looked into the code today, 
but I assume that RollingFileAppender has a Finalizer just like the FileStream 
has one. RollingFileAppender (Object A) references the FileStream (Object B) 
directly or indirectly. Finalization happens in undefined order: in my observed 
case, apparently the FileStream was finalized *before* the RollingFileAppender. 
Hence, RollingFileAppender failed to write a footer and flush the FileStream in 
its own finalizer implementation.


was (Author: m.hess):
Hi, I guess my point was this:
> The finalizers of two objects are not guaranteed to run in any specific 
> order, even if one object refers to the other. That is, if Object A has a 
> reference to Object B and both have finalizers, Object B might have already 
> been finalized when the finalizer of Object A starts.
taken from https://msdn.microsoft.com/en-us/library/system.object.finalize.aspx

I can't remember this issue exactly and I haven't looked into the code today, 
but I assume that RollingFileAppender has a Finalizer just like the FileStream 
has one. RollingFileAppender (Object A) references the FileStream (Object B) 
directly or indirectly. Finalization happens in undefined order: in my observed 
case, apparently the FileStream was finalized *before* the RollingFileAppender. 
Hence, RollingFileAppender failed to write a footer and flush the FileStream in 
its own finalizer implementation.

> Finalization of appenders might fail
> ------------------------------------
>
>                 Key: LOG4NET-501
>                 URL: https://issues.apache.org/jira/browse/LOG4NET-501
>             Project: Log4net
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.2.10
>            Reporter: Matthias Hess
>
> Given the following example:
> {code}
>             LogLog.InternalDebugging = true;
>             RollingFileAppender result = new RollingFileAppender();
>             result.File = ...;
>             result.AppendToFile = true;
>             result.Encoding = Encoding.UTF8;
>             ...
>             result.ActivateOptions();
> {code}
> When this rolling file appender object gets finalized (due to no more 
> references), the finalization code tries to close the underlying file stream. 
> This will fail, if the underlying file stream itself was already subject to 
> finalization.
> It gives me log4net internal error messages when using the appenders outside 
> of a logger repository.
> I think, the current finalization code does a little too much. Writing a 
> footer/flushing should be triggered by the AppDomain events only.
> What do you think about it?



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to