FreeAndNil commented on PR #369:
URL: https://github.com/apache/logging-log4net/pull/369#issuecomment-7052179292

   Implementation plan for #369, kept here for the record. Written up to 
describe the change as it stands on the branch.
   
   <details>
   <summary>Plan</summary>
   
   # Fixes from the 2026-11 audit, part 4: FileAppender
   
   ## Context
   
   The same scan as #355 reported, among the lows, problems with `FileAppender` 
sharing a file between
   processes: records overwritten or split with `ImmediateFlush=false`, 
`Flush(int)` discarding
   buffered text, `MinimalLock` letting two writers in at once outside Windows, 
and a timed-out open
   waiting four times per event. Two more turned up while fixing them: outside 
Windows the named
   mutexes are per session, and a retried `RollingFileAppender` open adds the 
roll suffix again.
   Three issues: #366 (flushing under shared locks), #367 (exclusion outside 
Windows), #368 (the
   retried open).
   
   ## Constraints that shape the design
   
   - `InterProcessLock` keeps its stream open and seeks to the end under the 
mutex; bytes buffered in
     `StreamWriter` or `FileStream` after the release land at a stale offset, 
over other processes'
     records. `MinimalLock` closes the stream, but buffered characters still 
land after another
     process's text.
   - The header and footer are written without a flush; the footer and the 
close ran under two
     separate locks.
   - `TextWriterAppender.Flush(int)` flushes without the file lock; the locking 
stream throws and the
     buffered text is lost.
   - On Linux `FileShare.Read` is a shared `flock`, and `FileMode.Append` is an 
offset read at open,
     so two `MinimalLock` writers write at the same end of file.
   - A mutex name without `Global\` is per session outside Windows.
   - No new public API in a patch release.
   
   ## Changes
   
   1. #368 A private `HasOpenWriter`: footer, close and header take no lock 
without an open writer, so
      a timed-out open waits once per event, not four times. A nested 
best-effort lock runs under the
      outer attempt instead of waiting again. `Reset()` disposes a stream left 
without a writer. A
      retried open always appends; `OpenFile` no longer stores its argument in 
`AppendToFile`.
   2. #366 With `InterProcessLock` and `MinimalLock` the writer is flushed 
before every release, for
      single and bulk appends, the header and a throwing layout; footer and 
close run under one lock.
      `ImmediateFlush=false` is ignored with these two models, warned once per 
`ActivateOptions`.
   3. #366 `FileAppender.Flush(int)` takes the appender lock, then the file 
lock, and flushes under
      both; it returns at once for `InterProcessLock` and `MinimalLock`, which 
flush before each
      release.
   4. #368 `RollingFileAppender` overrides `PrepareWriter` to retry with the 
base file name, so the
      roll suffix is added once.
   5. #367 Outside Windows the `InterProcessLock` and roll mutexes are named 
with `Global\`, added
      after the 255-byte limit of `MutexNameForPath`. Windows unchanged.
   6. #367 Outside Windows `MinimalLock` takes the same global mutex around 
each write, timeout
      10 seconds; readers are not blocked. When the runtime refuses the mutex 
(no writable home), one
      `LogLog` warning and logging goes on as before.
   
   Docs: `fileappender.adoc` and `faq.adoc` on `ImmediateFlush` with the shared 
locks and on the
   mutex scope (one host, one user account, a writable home), XML doc comments 
of the changed members.
   One changelog entry per change in `src/changelog/3.6.1`.
   
   ## Sequencing
   
   1. The retried open first; the flush and the footer change build on 
`HasOpenWriter`.
   2. The flush before release, then `Flush(int)`.
   3. The retry suffix.
   4. The global mutex names, then the `MinimalLock` mutex on top.
   5. Each commit: test against the unfixed code first, fix, mutate each 
changed line, review loop.
   6. Commits and pushes are the maintainer's.
   
   ## Verification
   
   - `dotnet build` of all targets with 0 warnings, tests on net10 and, on 
Windows, net462.
   - Two appenders on one file in-process: messages, header, footer over 1024 
characters and a
     throwing layout leave every record whole.
   - A counting `InterProcessLock` pins the lock waits: one per event after a 
failed open, none for
     `Close` without a writer.
   - `MinimalLock` outside Windows: a second writer waits for the first; a 
reader does not delay a
     write. Mutex names checked per platform; a `setsid` probe on .NET 10 
confirmed a plain name is
     per session and `Global\` is not.
   - Not covered, own issues later: a second `ActivateOptions` after `File` 
changed, and
     `InterProcessLock` and `RollingFileAppender` without a writable home.
   
   </details>
   


-- 
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]

Reply via email to