Skip to content

Fix TOCTOU race in LogOptions.CreateLogger (#252)#253

Merged
ptr727 merged 1 commit into
developfrom
fix/logoptions-createlogger-toctou
Jul 10, 2026
Merged

Fix TOCTOU race in LogOptions.CreateLogger (#252)#253
ptr727 merged 1 commit into
developfrom
fix/logoptions-createlogger-toctou

Conversation

@ptr727

@ptr727 ptr727 commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Fixes #252.

Problem

LogOptions.CreateLogger(string) read the LoggerFactory property twice — once for the ReferenceEquals guard and once for the actual CreateLogger call. Since the backing field is swapped with Interlocked.Exchange, a concurrent SetFactory could make the guard and the create observe different factory instances, defeating the thread-safe intent of the Volatile/Interlocked design.

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 sibling ptr727.Utilities fix (ptr727/Utilities#381).

Verification

dotnet test — build clean, 296/296 pass.

🤖 Generated with Claude Code

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]>
Copilot AI review requested due to automatic review settings July 10, 2026 04:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 LoggerFactory once into a local in CreateLogger(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

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.76%. Comparing base (0f2001b) to head (2f8fb65).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ptr727
ptr727 merged commit adba4dc into develop Jul 10, 2026
13 checks passed
@ptr727
ptr727 deleted the fix/logoptions-createlogger-toctou branch July 10, 2026 04:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants