Fix TwoWayAgent deadlock in TaskCompletionSource constructor#56
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a deadlock in TwoWayAgent.Tell() by correctly configuring TaskCompletionSource continuations to run asynchronously, and adds a regression test that reproduces the problematic synchronous-continuation scenario.
Changes:
- Replace incorrect
TaskContinuationOptions.RunContinuationsAsynchronouslyargument withTaskCreationOptions.RunContinuationsAsynchronouslywhen constructingTaskCompletionSourceinTwoWayAgent.Tell(). - Add a regression test that forces a synchronous continuation to call
Tell()again and validates it completes without blocking. - Normalize the test project file header (BOM removal / formatting-only change).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Dbosoft.Functional/Agent.cs | Fixes TaskCompletionSource construction so continuations don’t run inline on the ActionBlock thread. |
| test/Dbosoft.Functional.Tests/TwoWayAgentTests.cs | Adds regression coverage for the deadlock scenario via a synchronous continuation calling Tell() again. |
| test/Dbosoft.Functional.Tests/Dbosoft.Functional.Tests.csproj | Formatting-only change to the project file header. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ource constructor TaskCompletionSource<T> was created with TaskContinuationOptions.RunContinuationsAsynchronously which silently matched the (object? state) overload instead of configuring async continuations. This caused SetResult() to run continuations inline, deadlocking when a continuation called Tell() on the same agent. Fixes #55
65e76c8 to
4597201
Compare
- Fault or cancel the TaskCompletionSource when ActionBlock.Post() returns false, preventing callers from hanging indefinitely on a completed/canceled agent. - Remove unused System.Threading using in test file.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
TaskContinuationOptions→TaskCreationOptionsinTwoWayAgent.Tell()— the wrong enum was silently boxed asobjectstate instead of configuring async continuations, causing deadlocks when continuations callTell()on the same agent.Fixes #55
Test plan