Skip to content

Fix thread-safety issue in LogRecordSharedPool.Rent()#6833

Merged
rajkumar-rangaraj merged 9 commits intoopen-telemetry:mainfrom
kimjaejung96:fix/6233-logrecordsharedpool-threadsafe
Feb 17, 2026
Merged

Fix thread-safety issue in LogRecordSharedPool.Rent()#6833
rajkumar-rangaraj merged 9 commits intoopen-telemetry:mainfrom
kimjaejung96:fix/6233-logrecordsharedpool-threadsafe

Conversation

@kimjaejung96
Copy link
Copy Markdown
Contributor

@kimjaejung96 kimjaejung96 commented Jan 17, 2026

Fixes #6233

Changes

This PR fixes a thread-safety issue in LogRecordSharedPool.Rent() where the same LogRecord instance could be rented to multiple threads concurrently under high contention.

  • Fixed Race Condition: In Rent(), when TryRentCoreRare fails (due to a race), changed the behavior to break the loop and create a new LogRecord instance. Previously, it would continue and retry with a new index, which could lead to a duplicate rental.
  • Optimized Calculation: Extracted slotIndex calculation to avoid redundant modulo operations.
  • Added Regression Test: Added RentShouldNeverReturnSameInstanceConcurrently in LogRecordSharedPoolTests.cs to verify the fix.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] LogRecordSharedPool isn't thread safe

4 participants