[1.5] Port #7859 and #7875 to fix UnfoldResourceAsyncSourceSpec#8123
Merged
Arkatufus merged 3 commits intoMar 23, 2026
Conversation
…kkadotnet#7859) Changed UnfoldResourceSourceAsync to use InvokeWithFeedback instead of direct callback invocation to properly handle StreamDetachedException when the stream stops before resource creation completes. The previous implementation used Action<T> invocation which silently drops callbacks after stage shutdown. This caused resource cleanup to be skipped when streams were cancelled quickly (e.g., with Sink.Cancelled), leading to test timeouts waiting for close callbacks. The fix uses GetTypedAsyncCallback to obtain IAsyncCallback<T> and calls InvokeWithFeedback with an async local function pattern. This ensures StreamDetachedException is properly caught and resource cleanup occurs even when the callback cannot be processed due to stream completion. Fixes UnfoldResourceAsyncSourceSpec.A_UnfoldResourceAsyncSource_must_close_resource_when_stream_is_quickly_cancelled_reproducer_2 (cherry picked from commit ccad240)
Fixed a race condition where OfferAsync() calls could hang indefinitely when called during stream shutdown. The issue occurred when offers were accepted between CompleteStage()/FailStage() and PostStop(). The existing _terminating flag was only used to defer completion until buffer draining, but wasn't checked when processing new offers, allowing them to be accepted during shutdown but never completed. Solution: - Check _terminating at callback entry and immediately drop offers - Set _terminating=true in OnDownstreamFinish before CompleteStage() - Set _terminating=true in Failure handler before FailStage() - Set _terminating=true in buffer overflow Fail cases before FailStage() This aligns the .NET implementation with the upstream pattern where terminating offers are rejected immediately. Fixes flaky test: QueueSourceSpec.QueueSource_should_buffer_when_needed (cherry picked from commit 66cc6d6)
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