Fix TOCTOU race in LogOptions.CreateLogger (#252)#253
Merged
Conversation
Read LoggerFactory once into a local so a concurrent SetFactory swap cannot split the ReferenceEquals guard and the CreateLogger call across two different factory instances. Also splits the em-dash remark into two ASCII sentences, matching the sibling ptr727.Utilities fix. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens LogOptions.CreateLogger(string) against a TOCTOU race by ensuring the logger factory is read once and used consistently, aligning the method’s behavior with the intended Volatile/Interlocked thread-safety design.
Changes:
- Reads
LoggerFactoryonce into a local inCreateLogger(string)to avoid split guard/create observations across concurrent factory swaps. - Replaces an em-dash in the XML
<remarks>with two ASCII sentences to match repository documentation style.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #253 +/- ##
========================================
Coverage 99.76% 99.76%
========================================
Files 15 15
Lines 232993 232994 +1
Branches 243 243
========================================
+ Hits 232449 232450 +1
Misses 462 462
Partials 82 82 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Jul 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #252.
Problem
LogOptions.CreateLogger(string)read theLoggerFactoryproperty twice — once for theReferenceEqualsguard and once for the actualCreateLoggercall. Since the backing field is swapped withInterlocked.Exchange, a concurrentSetFactorycould make the guard and the create observe different factory instances, defeating the thread-safe intent of theVolatile/Interlockeddesign.Fix
Read the factory once into a local and use it for both the check and the create. Also splits the
<remarks>em-dash into two ASCII sentences, matching the siblingptr727.Utilitiesfix (ptr727/Utilities#381).Verification
dotnet test— build clean, 296/296 pass.🤖 Generated with Claude Code