FreeAndNil opened a new issue, #366:
URL: https://github.com/apache/logging-log4net/issues/366

   `InterProcessLock` and `MinimalLock` let several processes write one file. 
With
   `ImmediateFlush=false`, buffered text outlives the lock:
   
   - `InterProcessLock` keeps the `FileStream` open. Its buffered bytes are 
bound to the end of file seen
     under the lock; another process appends there, and the next write puts the 
stale bytes over its
     records. Records are lost without any report. ANT-2026-EAZMFSKC.
   - The `StreamWriter` keeps up to 1024 characters, which land after another 
process's text, so
     records are split. `MinimalLock` closes its stream per event, but splits 
records the same way.
   - A header over 1024 characters overwrites another process's records, also 
with
     `ImmediateFlush=true`; the footer is written under two separate locks.
   - A layout that throws halfway leaves its text in the buffer, for both 
`ImmediateFlush` values.
   - `Flush(int)` flushes without the file lock, so the locking stream refuses, 
`Flush` returns
     `false`, and the buffered text is discarded. ANT-2026-98BDXCN5.
   
   Proposed fix: with these two locking models, flush before releasing the lock 
on every append and
   after the header, so `ImmediateFlush=false` has no effect there; log a 
warning once when it is set.
   Write footer and close under one lock. Let `FileAppender.Flush(int)` take 
the appender lock and the
   file lock before flushing. For speed, put a `BufferingForwardingAppender` in 
front: one lock and one
   flush per batch.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

  • [I] ImmediateFlush=false with sh... FreeAndNil (via GitHub) via notifications

Reply via email to