Fix race condition in QueueSink causing async enumerable timeout#7973
Merged
Aaronontheweb merged 2 commits intoakkadotnet:devfrom Dec 22, 2025
Aaronontheweb:claude-wt-AsyncEnumerableSpec.RunAsAsyncEnumerable_Throws_on_Abrupt_Stream_termination
Conversation
Fixed a timing-dependent race condition where RunAsAsyncEnumerable would timeout when the materializer shut down while a PullAsync() request was pending. The QueueSink.Logic.PostStop() method now properly completes any pending TaskCompletionSource stored in _currentRequest with a StreamDetachedException before shutting down, preventing orphaned Tasks that would never complete. This resolves intermittent test failures in AsyncEnumerableSpec.RunAsAsyncEnumerable_Throws_on_Abrupt_Stream_termination where the test would hang waiting for an exception that never arrived.
Aaronontheweb
commented
Dec 22, 2025
| public override void PostStop() | ||
| { | ||
| // Complete any pending request before shutting down to prevent orphaned Tasks | ||
| if (_currentRequest.HasValue) |
Member
Author
There was a problem hiding this comment.
Need to do this otherwise the IAsyncEnumerable hangs on the _currentRequest value
…rable_Throws_on_Abrupt_Stream_termination
Arkatufus
pushed a commit
to Arkatufus/akka.net
that referenced
this pull request
Jan 7, 2026
…adotnet#7973) Fixed a timing-dependent race condition where RunAsAsyncEnumerable would timeout when the materializer shut down while a PullAsync() request was pending. The QueueSink.Logic.PostStop() method now properly completes any pending TaskCompletionSource stored in _currentRequest with a StreamDetachedException before shutting down, preventing orphaned Tasks that would never complete. This resolves intermittent test failures in AsyncEnumerableSpec.RunAsAsyncEnumerable_Throws_on_Abrupt_Stream_termination where the test would hang waiting for an exception that never arrived.
Aaronontheweb
added a commit
that referenced
this pull request
Jan 8, 2026
Fixed a timing-dependent race condition where RunAsAsyncEnumerable would timeout when the materializer shut down while a PullAsync() request was pending. The QueueSink.Logic.PostStop() method now properly completes any pending TaskCompletionSource stored in _currentRequest with a StreamDetachedException before shutting down, preventing orphaned Tasks that would never complete. This resolves intermittent test failures in AsyncEnumerableSpec.RunAsAsyncEnumerable_Throws_on_Abrupt_Stream_termination where the test would hang waiting for an exception that never arrived.
This was referenced Jan 9, 2026
This was referenced Feb 11, 2026
This was referenced Feb 20, 2026
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
Fixed a timing-dependent race condition where
RunAsAsyncEnumerablewould timeout when the materializer shut down while aPullAsync()request was pending.Changes
QueueSink.Logic.PostStop()to properly complete any pendingTaskCompletionSourcestored in_currentRequestwith aStreamDetachedExceptionbefore shutting downIssue
This resolves intermittent test failures in
AsyncEnumerableSpec.RunAsAsyncEnumerable_Throws_on_Abrupt_Stream_terminationwhere the test would hang waiting for an exception that never arrived.Root Cause
When the materializer shut down abruptly, the
PostStop()method only set up a callback handler for future pull requests but didn't clean up already-pending requests waiting for data. The pendingTaskCompletionSourcein_currentRequestwould remain incomplete, causing the async enumerable to hang indefinitely.Testing