FreeAndNil commented on PR #365:
URL: https://github.com/apache/logging-log4net/pull/365#issuecomment-7047842761
Implementation plan for #365, 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 3
## Context
The same scan as #355 reported, among the lows, five problems around fixing
a `LoggingEvent` so a
buffering appender can send it later from another thread: context gets lost
for later appenders of
the same call, or is taken from the flushing thread or request. One more
turned up while fixing
them, and a second `ActivateOptions` on a buffering appender drops its
buffer. Two issues: #362
(the fix lock, buffered properties, the `%aspnet-*` converters, the property
flattening) and #363
(the buffer on reactivation).
The rule behind every fix: a value that used to be wrong is now empty, never
taken from another
thread or request.
## Constraints that shape the design
- One `LoggingEvent` goes to every appender of a logging call; a buffering
appender fixes it, and
everything after that sees the fixed state.
- `FixVolatileData` locked the cache for all fields, and reopened it on
whatever thread asked for a
flag the event lacked.
- `LookupProperty` and `GetProperties` composed the reading thread's
`ThreadContext` and
`LogicalThreadContext`, so a flush read the flusher's properties.
- `CompositeProperties.Flatten` published its dictionary before filling it.
- `%aspnet-context`, `%aspnet-request` and `%aspnet-session` read
`HttpContext.Current` when the
event is rendered, which behind a buffer is the flushing request.
- No new public API in a patch release, and no `System.Web` load into
processes that do not use an
`%aspnet-*` converter.
## Changes
1. #362 `LoggingEvent`: one field `_deliveryThreadId`, set by
compare-exchange in
`Logger.CallAppenders` and cleared in a `finally`; `CanCache` is true
while the event is
unfixed or on the delivering thread. The lazy getters and
`CacheProperties` use it, so later
appenders of the same call see every field. `FixVolatileData` never
reopens the cache: off the
delivering thread it leaves out `Identity`, `LocationInfo` and
`ThreadName`, and writes the
thread-independent fields (message, exception text, domain) directly.
2. #362 Properties off the delivering thread: `LookupProperty` and
`GetProperties` compose the
event's own and the global properties only, never the reading thread's
contexts, in a field of
their own. A fix with `Properties`, `Mdc` or `Ndc` there stores a
snapshot of that detached
composite, unless another thread is still delivering the event.
`FixFlags.Mdc` and `Ndc` fix
the properties.
3. #362 `CompositeProperties.Flatten` builds the dictionary first and
publishes it with
`Interlocked.CompareExchange`, so a second reader never sees it half
filled.
4. #363 `BufferingAppenderSkeleton.ActivateOptions`, under the appender
lock: the same size keeps
the buffer; any other size sends the old buffer with `Flush(true)`, as
`Close` does, then
installs the new one. A throwing `SendBuffer` is reported and does not
keep the new buffer out.
5. #362 `%aspnet-context`, `%aspnet-request`, `%aspnet-session` (net462
only): the converters
register one internal `IFixingRequired` as the global property
`log4net:AspNetRequest`. A fix
with `Properties` turns it into a token for the logging request, from a
`ConditionalWeakTable<HttpContext, RequestToken>`, so no request is kept
alive. At render time a
fixed event whose token is not the current request's writes `NOT
AVAILABLE`. `%aspnet-cache` is
application wide and stays as it is. Holes, documented: a buffer whose
`fix` leaves out
`Properties`, and an event first fixed off the logging thread. An event
built from
`LoggingEventData` or deserialized has no token and shows `NOT AVAILABLE`.
6. `AspNetPatternConverter.cs` renamed to match its class
`AspNetPatternLayoutConverter`, and the
pattern reference moved from the `PatternLayout` doc comment to a manual
page of its own,
`layouts/patterns.adoc`, in commits of their own.
Docs: `bufferingforwardingappender.adoc` on what `Partial` leaves out, the
new patterns page with
the ASP.NET section, the XML doc comments of the changed members. One
changelog entry per change in
`src/changelog/3.6.1`.
## Sequencing
1. The fix lock and the delivering thread first; everything else depends on
it.
2. Properties off the delivering thread, then the flattening found while
doing it.
3. The buffer on reactivation.
4. The `%aspnet-*` converters, after the property changes they build on,
with the rename and the
docs move in front.
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.
- Overlapping deliveries across threads, deterministic: a thread handing the
event to another one
while it still delivers.
- `%aspnet-*`: hand-built `HttpContext`s on net462, events through a buffer.
Fresh `AppDomain`s
show that `System.Web` stays unloaded without an `%aspnet-*` pattern and
that only the three
request converters register the capture. An ended request is collected
while its buffered event
lives. Ten mutants of the capture, all caught on Windows CI.
</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]