fix: Fix critical deadlock and hanging issues in async processors - #311
Merged
Conversation
## Changes Made: ### 1. Fixed cancellation handling in EnumerableExtensions - Added proper CancellationToken support to ToIAsyncEnumerable method - While loop now properly responds to cancellation requests - Prevents infinite hanging when tasks don't complete ### 2. Fixed semaphore release bug in ParallelExtensions - Only releases semaphore if it was successfully acquired - Prevents SemaphoreFullException when cancellation occurs during WaitAsync - Tracks acquisition state properly in both ProcessAsync overloads ### 3. Removed unnecessary Task.Run wrapping - Eliminated redundant Task.Run in rate-limited processors - Removed Task.Run wrapping for already-async operations in ParallelExtensions - Fixed Task.Run + Task.Yield redundancy (just using Task.Yield where needed) ### 4. Improved unbounded processor implementations - AsyncEnumerableUnboundedParallelProcessor now truly unbounded (no artificial limits) - Trusts .NET ThreadPool to manage resources appropriately - Enhanced documentation warnings about resource risks - Maintains backward compatibility ### 5. Performance improvements - Removed wasteful counting/enumeration operations - Eliminated double context switching from Task.Run + Task.Yield - Let runtime handle thread pool scheduling optimally These fixes address the critical issues identified in the deadlock analysis while maintaining the library's performance characteristics and backward compatibility. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
thomhurst
temporarily deployed
to
Pull Requests
August 10, 2025 17:02 — with
GitHub Actions
Inactive
thomhurst
enabled auto-merge
August 10, 2025 17:02
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 Made:
1. Fixed cancellation handling in EnumerableExtensions
2. Fixed semaphore release bug in ParallelExtensions
3. Removed unnecessary Task.Run wrapping
4. Improved unbounded processor implementations
5. Performance improvements
These fixes address the critical issues identified in the deadlock analysis while maintaining the library's performance characteristics and backward compatibility.
🤖 Generated with Claude Code