[OpenTelemetry] Fix SemaphoreSlim leak#7069
Merged
Kielek merged 3 commits intoopen-telemetry:mainfrom Apr 14, 2026
Merged
Conversation
Fix `SemaphoreSlim.WaitAsync()` waiter leak.
Add CHANGELOG entry.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Contributor
There was a problem hiding this comment.
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 linkedCancellationTokenSourceto preventSemaphoreSlimwaiter 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.mdwith 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.
Address Copilot review feedback.
Kielek
approved these changes
Apr 14, 2026
Merged
via the queue into
open-telemetry:main
with commit Apr 14, 2026
d94e779
121 of 122 checks passed
This was referenced Apr 21, 2026
This was referenced Apr 21, 2026
Open
Open
Open
Open
Open
Open
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.
Changes
Fix
SemaphoreSlim.WaitAsync()waiter leak.Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)