FreeAndNil commented on code in PR #323:
URL: https://github.com/apache/logging-log4net/pull/323#discussion_r4085777473
##########
src/log4net.Tests/Core/FixingTest.cs:
##########
@@ -210,6 +212,45 @@ public void UserNameIsCapturedWhenItIsFixed()
Assert.That(loggingEvent.UserName,
Is.Not.EqualTo(SystemInfo.NotAvailableText));
}
+ /// <summary>
+ /// A redundant Fix must not reopen the cache: a thread reading a field the
event never captured
+ /// would otherwise store its own principal in it. 500000 calls, the defect
hit within 63000.
+ /// </summary>
+ [Test]
+ public void ARedundantFixDoesNotLetAnotherThreadCacheItsIdentity()
+ {
+ LoggingEvent loggingEvent = CreateEvent();
+ // Partial leaves Identity out, so it stays null unless the cache reopens.
+ loggingEvent.Fix = FixFlags.Partial;
+
+ bool stop = false;
+ long spins = 0;
+ TaskCompletionSource<bool> running = new();
+ Thread reader = new(() =>
+ {
+ Thread.CurrentPrincipal = new GenericPrincipal(new
GenericIdentity("Intruder"), null);
+ running.TrySetResult(true);
+ while (!Volatile.Read(ref stop) && loggingEvent.Identity is null)
+ {
+ Interlocked.Increment(ref spins);
Review Comment:
- timed it, the whole test is done in 34 ms
- the reader only spins while the writer runs its 500000 Fix calls, then it
gets stopped
- it has to be that hot: on the broken build the bug took 56000 to 63000
reads to show up
- a yield in there would just hide it again
--
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]