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)

Fixes open-telemetry#6233

- Change TryRentCoreRare failure handling from 'continue' to 'break' to prevent duplicate LogRecord rentals under high contention
- Optimize slotIndex calculation
- Add regression test RentShouldNeverReturnSameInstanceConcurrently
@kimjaejung96 kimjaejung96 requested a review from a team as a code owner January 17, 2026 05:42
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Jan 17, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: rajkumar-rangaraj / name: Rajkumar Rangaraj (d5323a2)

@github-actions github-actions bot added the pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package label Jan 17, 2026
@kimjaejung96
Copy link
Copy Markdown
Contributor Author

kimjaejung96 commented Jan 22, 2026

Hi.

@alanwest @open-telemetry/dotnet-approvers could you please review this? It addresses the thread-safety issue in LogRecordSharedPool (Fixes #6233).

@TimothyMothra, tagging you as well since this is in the Logs/LogRecord pool area.

Also, this is my first time requesting a review in this repo—if I’m not tagging the right people or there’s a preferred process, please let me know and I’ll follow it.

@github-actions
Copy link
Copy Markdown
Contributor

This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or pushing will instruct the bot to automatically remove the label. This bot runs once per day.

@github-actions github-actions bot added the Stale Issues and pull requests which have been flagged for closing due to inactivity label Jan 29, 2026
@Kielek Kielek removed the Stale Issues and pull requests which have been flagged for closing due to inactivity label Jan 29, 2026
Copy link
Copy Markdown
Member

@martincostello martincostello left a comment

Choose a reason for hiding this comment

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

Please update the CHANGELOG with the bug fix details.

- Add CHANGELOG entry for thread-safety fix in LogRecordSharedPool.Rent()
- Use ConcurrentQueue for duplicate detection messages in test to avoid race condition when collecting failure details"
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.28%. Comparing base (86c7a90) to head (d5323a2).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6833      +/-   ##
==========================================
+ Coverage   86.35%   87.28%   +0.92%     
==========================================
  Files         263      263              
  Lines       12387    12388       +1     
==========================================
+ Hits        10697    10813     +116     
+ Misses       1690     1575     -115     
Flag Coverage Δ
unittests-Project-Experimental 85.91% <100.00%> (-0.35%) ⬇️
unittests-Project-Stable 86.19% <100.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/OpenTelemetry/Logs/Pool/LogRecordSharedPool.cs 100.00% <100.00%> (ø)

... and 8 files with indirect coverage changes

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 7, 2026

This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or pushing will instruct the bot to automatically remove the label. This bot runs once per day.

@github-actions github-actions bot added the Stale Issues and pull requests which have been flagged for closing due to inactivity label Feb 7, 2026
@kimjaejung96
Copy link
Copy Markdown
Contributor Author

Hi @martincostello — re-requesting review 🙇
Please let me know if there's anything else I should update.

@github-actions github-actions bot removed the Stale Issues and pull requests which have been flagged for closing due to inactivity label Feb 8, 2026
@rajkumar-rangaraj rajkumar-rangaraj added this pull request to the merge queue Feb 17, 2026
This was referenced Mar 28, 2026
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