Skip to content

[OpenTelemetry] Fix SemaphoreSlim leak#7069

Merged
Kielek merged 3 commits intoopen-telemetry:mainfrom
martincostello:batch-exporter-wasm-fix
Apr 14, 2026
Merged

[OpenTelemetry] Fix SemaphoreSlim leak#7069
Kielek merged 3 commits intoopen-telemetry:mainfrom
martincostello:batch-exporter-wasm-fix

Conversation

@martincostello
Copy link
Copy Markdown
Member

Changes

Fix SemaphoreSlim.WaitAsync() waiter leak.

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)

Fix `SemaphoreSlim.WaitAsync()` waiter leak.
@github-actions github-actions Bot added the pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package label Apr 13, 2026
Add CHANGELOG entry.
@martincostello martincostello requested a review from Kielek April 13, 2026 16:08
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.61%. Comparing base (a2b6372) to head (f0b6a9e).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7069      +/-   ##
==========================================
+ Coverage   88.54%   88.61%   +0.07%     
==========================================
  Files         270      270              
  Lines       12884    12938      +54     
==========================================
+ Hits        11408    11465      +57     
+ Misses       1476     1473       -3     
Flag Coverage Δ
unittests-Project-Experimental 88.60% <100.00%> (+0.14%) ⬆️
unittests-Project-Stable 88.20% <100.00%> (-0.27%) ⬇️

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

Files with missing lines Coverage Δ
...rc/OpenTelemetry/Internal/BatchExportTaskWorker.cs 44.66% <100.00%> (+6.79%) ⬆️
...nternal/PeriodicExportingMetricReaderTaskWorker.cs 75.00% <100.00%> (+9.32%) ⬆️

... and 4 files with indirect coverage changes

@martincostello martincostello marked this pull request as ready for review April 13, 2026 16:32
@martincostello martincostello requested a review from a team as a code owner April 13, 2026 16:32
Copilot AI review requested due to automatic review settings April 13, 2026 16:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a SemaphoreSlim.WaitAsync() waiter leak in task-based workers used when threading is disabled (e.g., Blazor/WASM), ensuring TriggerExport() can reliably wake the worker loop without accumulating orphaned waiters.

Changes:

  • Cancel both the delay and exportTrigger.WaitAsync(...) using a linked CancellationTokenSource to prevent SemaphoreSlim waiter leaks in task-based workers.
  • Add new unit tests validating that trigger-based exports/collects don’t wait for the scheduled delay/export interval after the worker has been idle.
  • Update src/OpenTelemetry/CHANGELOG.md with a note about the resource leak fix.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
test/OpenTelemetry.Tests/Internal/TaskWorkerTests.cs Adds regression tests for trigger responsiveness after idle cycles in task-based workers.
src/OpenTelemetry/Internal/PeriodicExportingMetricReaderTaskWorker.cs Cancels WaitAsync waiters when the delay wins, avoiding leaked semaphore waiters.
src/OpenTelemetry/Internal/BatchExportTaskWorker.cs Cancels WaitAsync waiters when the delay wins, avoiding leaked semaphore waiters.
src/OpenTelemetry/CHANGELOG.md Documents the resource leak fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/OpenTelemetry/CHANGELOG.md Outdated
Comment thread test/OpenTelemetry.Tests/Internal/TaskWorkerTests.cs
Comment thread test/OpenTelemetry.Tests/Internal/TaskWorkerTests.cs Outdated
Comment thread test/OpenTelemetry.Tests/Internal/TaskWorkerTests.cs Outdated
Address Copilot review feedback.
This was referenced Apr 21, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants