Skip to content

fix: Fix deadlock issues in async processors - #307

Merged
thomhurst merged 1 commit into
mainfrom
fix/deadlock-issues
Aug 9, 2025
Merged

fix: Fix deadlock issues in async processors#307
thomhurst merged 1 commit into
mainfrom
fix/deadlock-issues

Conversation

@thomhurst

Copy link
Copy Markdown
Owner
  • Fix TaskCompletionSource not being set on exceptions in ProcessOrderedItemAsync Previously, if _taskSelector threw an exception, no TaskCompletionSource was added to the ordering dictionary, causing infinite waits. Now always add TCS first, then set result/exception appropriately.

  • Replace GetAwaiter().GetResult() with Task.Run + timeout in Dispose methods Prevents synchronization context deadlocks in UI/ASP.NET contexts by running async disposal on thread pool with 30-second timeout.

  • Add proper exception handling to channel.Writer.Complete() calls Ensures channels are properly completed even when exceptions occur during producer/consumer task execution. Uses finally blocks to guarantee completion regardless of where exceptions are thrown.

🤖 Generated with Claude Code

- Fix TaskCompletionSource not being set on exceptions in ProcessOrderedItemAsync
  Previously, if _taskSelector threw an exception, no TaskCompletionSource was added
  to the ordering dictionary, causing infinite waits. Now always add TCS first, then
  set result/exception appropriately.

- Replace GetAwaiter().GetResult() with Task.Run + timeout in Dispose methods
  Prevents synchronization context deadlocks in UI/ASP.NET contexts by running
  async disposal on thread pool with 30-second timeout.

- Add proper exception handling to channel.Writer.Complete() calls
  Ensures channels are properly completed even when exceptions occur during
  producer/consumer task execution. Uses finally blocks to guarantee completion
  regardless of where exceptions are thrown.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@thomhurst
thomhurst enabled auto-merge August 9, 2025 00:16
@thomhurst
thomhurst merged commit 6d672d2 into main Aug 9, 2025
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant