GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stop stale context reaching logical stacks and fixed events by FreeAndNil · Pull Request #323 · apache/logging-log4net

Conversation

@FreeAndNil

@FreeAndNil FreeAndNil commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Fixed

  • Logical stack brought back old frames, audit da18b6f-f044
    • Dispose used the copy of the stack made at Push time
    • after Clear, or after two Pop calls, the old frames came back
    • it now cuts the stack that is in use and never adds to it
    • known limit: disposing a frame of another flow cuts this flow, so frames can be lost, but
      nothing is added
  • A second Fix opened the event cache again, audit da18b6f-f039
    • the cache was opened before we knew if there was anything to fix
    • another thread could then write its own identity, thread name or location into the event
    • before the fix: one hit after 56000 to 63000 calls, five runs of five. After: none in 2000000

Deprecated

  • log4net.Util.TwoArgAction, the old callback of the stack, now unused, to be removed in v4

Documented, not changed

  • %property in a PatternString-typed setting, audit da18b6f-f021
    • a path built from such a value is the operator's choice, see the model and the FAQ on path
      traversal
    • cleaning the value in the converter would change it everywhere, and in the wrong place
  • AspNetTraceAppender belongs to one request, audit da18b6f-f006
    • behind a buffering appender, a flush writes into the request that caused it
    • dropping older events instead would lose them, which is worse

Speed of the stack change

1M calls, best of 5, Release on net10.0:

case before after
push and dispose, depth 1 405 to 438 ns, 1272 B 412 to 458 ns, 1272 B
push and dispose, depth 3 1386 to 1433 ns, 3976 B 1414 to 1440 ns, 3976 B
dispose after Clear 548 ns, 1656 B 361 ns, 1016 B

The normal cases are the same within noise and use the same memory. The fixed case is 34 percent
faster.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@FreeAndNil FreeAndNil added this to the 3.5.0 milestone Sep 20, 2026
FreeAndNil added a commit that referenced this pull request Sep 21, 2026
@FreeAndNil
point %property at the path traversal FAQ #323
58dd1e0
- context value into a PatternString-typed config value: the operator's choice
- trustworthiness of that value: the deployer's responsibility
- comment at the converter, note in our FAQ, where the next reader looks

audit da18b6f-f021, no code change.
FreeAndNil added a commit that referenced this pull request Sep 21, 2026
@FreeAndNil
say that the ASP.NET trace appender is request scoped #323
0558108
- writes to HttpContext.Current of the appending thread
- behind a buffering appender a flush hits the triggering request
- a timestamp filter would drop foreign events, so documented not enforced

audit da18b6f-f006, no code change.
FreeAndNil added a commit that referenced this pull request Sep 21, 2026
@FreeAndNil
stop a disposed logical stack frame restoring removed frames #323
f0fed53
- Dispose rebuilt the stack from the copy taken at Push time
- after Clear, or after a Pop below its depth, the earlier frames came back
- now trims the stack registered in the flow, never grows it
- the stack holds its owning stacks instead of a register callback
- residual: a foreign frame trims the current flow, loss not injection

1M ops, best of 5, Release on net10.0:

| case                 | before                  | after                   |
|----------------------|-------------------------|-------------------------|
| push/dispose depth 1 | 405 to 438 ns, 1272 B   | 412 to 458 ns, 1272 B   |
| push/dispose depth 3 | 1386 to 1433 ns, 3976 B | 1414 to 1440 ns, 3976 B |
| dispose after Clear  | 548 ns, 1656 B          | 361 ns, 1016 B          |

audit da18b6f-f044.
FreeAndNil added a commit that referenced this pull request Sep 21, 2026
@FreeAndNil
deprecate TwoArgAction #323
cbab042
- existed for the logical stack's register callback, now an owner reference
- unused in the tree, public so it stays for now
- marked obsolete, removal in version 4
@FreeAndNil
FreeAndNil force-pushed the Feature/323-event-and-context-state branch from e123b49 to 4ef6dea Compare September 21, 2026 18:21
FreeAndNil added a commit that referenced this pull request Sep 21, 2026
@FreeAndNil
unlock the event cache only while fixing #323
4ef6dea
- the cache was unlocked before the fields to fix were determined
- a redundant Fix reopened it with nothing to do
- a reader then cached its own identity, thread name or location
- measured: a hit after 56000 to 63000 calls, five runs of five

audit da18b6f-f039.
FreeAndNil added 5 commits September 22, 2026 21:05
@FreeAndNil
point %property at the path traversal FAQ #323
2aa6361
- context value into a PatternString-typed config value: the operator's choice
- trustworthiness of that value: the deployer's responsibility
- comment at the converter, note in our FAQ, where the next reader looks

audit da18b6f-f021, no code change.
@FreeAndNil
say that the ASP.NET trace appender is request scoped #323
a2f7c25
- writes to HttpContext.Current of the appending thread
- behind a buffering appender a flush hits the triggering request
- a timestamp filter would drop foreign events, so documented not enforced

audit da18b6f-f006, no code change.
@FreeAndNil
stop a disposed logical stack frame restoring removed frames #323
21c144a
- Dispose rebuilt the stack from the copy taken at Push time
- after Clear, or after a Pop below its depth, the earlier frames came back
- now trims the stack registered in the flow, never grows it
- the stack holds its owning stacks instead of a register callback
- residual: a foreign frame trims the current flow, loss not injection

1M ops, best of 5, Release on net10.0:

| case                 | before                  | after                   |
|----------------------|-------------------------|-------------------------|
| push/dispose depth 1 | 405 to 438 ns, 1272 B   | 412 to 458 ns, 1272 B   |
| push/dispose depth 3 | 1386 to 1433 ns, 3976 B | 1414 to 1440 ns, 3976 B |
| dispose after Clear  | 548 ns, 1656 B          | 361 ns, 1016 B          |

audit da18b6f-f044.
@FreeAndNil
deprecate TwoArgAction #323
872ca00
- existed for the logical stack's register callback, now an owner reference
- unused in the tree, public so it stays for now
- marked obsolete, removal in version 4
@FreeAndNil
unlock the event cache only while fixing #323
e725966
- the cache was unlocked before the fields to fix were determined
- a redundant Fix reopened it with nothing to do
- a reader then cached its own identity, thread name or location
- measured: a hit after 56000 to 63000 calls, five runs of five

audit da18b6f-f039.
@FreeAndNil
FreeAndNil force-pushed the Feature/323-event-and-context-state branch from 4ef6dea to e725966 Compare September 22, 2026 19:05
@FreeAndNil
FreeAndNil marked this pull request as ready for review September 22, 2026 19:07
@FreeAndNil
FreeAndNil requested review from fluffynuts and gdziadkiewicz September 22, 2026 19:08
fluffynuts
fluffynuts approved these changes Sep 23, 2026
View reviewed changes
gdziadkiewicz
gdziadkiewicz approved these changes Sep 23, 2026
View reviewed changes
@gdziadkiewicz
gdziadkiewicz requested a lite review from Copilot September 23, 2026 15:26
Copilot AI reviewed Sep 23, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 2 Medium severity

Open (2)
  • Medium severity This is a tight busy-spin loop that can peg a CPU core during the test run, increasing… · New
  • Medium severity The added sentence at line 51 is not prefixed like the surrounding table rows (||...). As… · New
What changed in this PR

Fixes two concurrency/context bugs in log4net: (1) disposed LogicalThreadContext.Stacks frames resurrecting removed frames, and (2) redundant LoggingEvent.Fix reopening the event cache and allowing cross-thread contamination.

Changes:

  • Rework LogicalThreadContextStack ownership/registration so Dispose trims the currently-registered stack rather than restoring a stale copy, plus new regression tests.
  • Change LoggingEvent.FixVolatileData to only unlock the cache when there is actual work to do and make _cacheUpdatable volatile, plus a new multithreaded regression test.
  • Documentation/changelog updates for %property path traversal considerations, AspNetTraceAppender constraints, and deprecation of TwoArgAction.
File Description
src/​site/​antora/​modules/​ROOT/​pages/​manual/​faq.adoc Adds security note about %property expansion and path traversal risk.
src/​site/​antora/​modules/​ROOT/​pages/​manual/​configuration/​appenders.adoc Documents AspNetTraceAppender request/thread affinity constraint.
src/​log4net/​Util/​PatternStringConverters/​PropertyPatternConverter.cs Adds in-code comment referencing path-traversal guidance for %property.
src/​log4net/​Util/​LogicalThreadContextStacks.cs Changes stack creation to pass owner; adds owner APIs for current-stack lookup/registration.
src/​log4net/​Util/​LogicalThreadContextStack.cs Replaces callback delegate with owner reference; fixes Dispose to trim current flow.
src/​log4net/​Core/​LoggingEvent.cs Prevents redundant Fix from reopening cache; makes cache flag volatile.
src/​log4net/​Appender/​AspNetTraceAppender.cs Adds remarks warning not to wrap in buffering appenders.
src/​log4net.Tests/​Core/​FixingTest.cs Adds regression test for cross-thread identity caching via redundant Fix.
src/​log4net.Tests/​Context/​LogicalThreadContextTest.cs Adds regression tests for stack dispose not resurrecting frames across clear/pop/flows.
src/​changelog/​3.5.0/​323-logical-stack-dispose.xml Changelog entry for logical stack dispose fix.
src/​changelog/​3.5.0/​323-logging-event-fix-cache.xml Changelog entry for logging-event cache reopening fix.
src/​changelog/​3.5.0/​323-deprecate-twoargaction.xml Changelog entry for TwoArgAction deprecation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/log4net.Tests/Core/FixingTest.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/site/antora/modules/ROOT/pages/manual/configuration/appenders.adoc Resolved

Uh oh!

There was an error while loading. Please reload this page.

Copilot started reviewing on behalf of gdziadkiewicz September 23, 2026 16:26
View session
@FreeAndNil
FreeAndNil merged commit fcdfc78 into master Sep 23, 2026
4 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@FreeAndNil
FreeAndNil deleted the Feature/323-event-and-context-state branch September 23, 2026 18:19
This was referenced Oct 1, 2026
Bump the all-nuget-updates group with 5 updates drmoisan/TaskMaster#962
Closed
Bump the nuget-dependencies group with 13 updates SvenGroot/JumboCore#65
Closed
Bump log4net and 11 others SvenGroot/JumboCore#66
Closed
Bump log4net from 3.4.0 to 3.5.0 loresoft/KickStart#327
Merged
Bump log4net from 3.4.0 to 3.5.0 ParadoxGameConverters/PGCG.commonItems#941
Merged
Bump log4net from 3.3.1 to 3.5.0 bbtsoftware/AzureDevOpsPolicyConfigurator#253
Closed
Bump the dependencies group with 5 updates guibranco/CrispyWaffle#1000
Merged
This was referenced Nov 12, 2026
Bump the nuget-dependencies group with 14 updates SvenGroot/JumboCore#78
Closed
Bump Crc32.NET and 12 others SvenGroot/JumboCore#79
Closed
Bump log4net from 3.3.2 to 3.5.0 jasonlandreth/GarminR10-BLE-Connector#6
Closed
DEV: Bump log4net from 3.4.0 to 3.5.0 origam/origam#5193
Merged
DEV: Bump log4net from 3.4.0 to 3.5.0 origam/origam#5194
Merged
DEV: Bump log4net from 3.4.0 to 3.5.0 origam/origam#5195
Merged
DEV: Bump log4net from 3.4.0 to 3.5.0 origam/origam#5196
Merged
DEV: Bump log4net from 3.4.0 to 3.5.0 origam/origam#5197
Merged
DEV: Bump log4net from 3.4.0 to 3.5.0 origam/origam#5198
Merged
Bump log4net from 3.3.0 to 3.5.0 chutch3/kenku#87
Merged
Bump log4net from 2.0.15 to 3.6.0 sg-scale/NETworkManager--2022.12.20.0#5
Open
Bump the minor-version-updates group with 4 updates PxTools/PCAxis.Menu.OracleDatamodelMenu#115
Merged
Bump log4net and 3 others PxTools/PCAxis.Metadata#108
Merged
Bump Crc32.NET and 12 others SvenGroot/JumboCore#80
Closed
Bump the nuget-dependencies group with 14 updates SvenGroot/JumboCore#81
Closed
Bump log4net and 4 others PxTools/PCAxis.Menu.MsSqlDatamodelMenu#114
Merged
Bump log4net and 3 others PxTools/PXWeb.SavedQuery.Oracle#119
Merged
Bump log4net and 4 others PxTools/PCAxis.Core#142
Merged
Bump log4net from 3.3.1 to 3.6.0 bbtsoftware/AzureDevOpsPolicyConfigurator#255
Open
Bump the minor-version-updates group with 4 updates PxTools/PCAxis.Menu#100
Merged
Bump log4net and 3 others PxTools/PCAxis.Query#113
Merged
Bump log4net and PCAxis.Core PxTools/PCAxis.Query#114
Closed
Bump log4net from 2.0.8 to 3.6.0 devsecops-lab-luis/demo-ghas-multilenguaje#27
Open
Dependency (dependabot/nuget): Bump log4net from 3.3.0 to 3.6.0 Nevergoodstudy/NETworkManager-macOS#24
Open
Bump the nuget-dependencies group with 14 updates SvenGroot/JumboCore#82
Open
Bump Crc32.NET and 12 others SvenGroot/JumboCore#83
Open
deps: Bump log4net from 3.3.2 to 3.6.0 OliverRetro/WavePlus#62
Open
Bump log4net from 3.3.1 to 3.6.0 bNobo/needabreak#176
Open
This was referenced Nov 19, 2026
Bump log4net from 3.3.2 to 3.6.0 jasonlandreth/GarminR10-BLE-Connector#7
Open
Bump Crc32.NET and 12 others SvenGroot/JumboCore#84
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@fluffynuts fluffynuts fluffynuts approved these changes
@gdziadkiewicz gdziadkiewicz gdziadkiewicz approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

3.5.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@FreeAndNil @fluffynuts @gdziadkiewicz
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.