Skip to content

[1.5] Port #7859 and #7875 to fix UnfoldResourceAsyncSourceSpec#8123

Merged
Arkatufus merged 3 commits into
akkadotnet:v1.5from
Arkatufus:1.5/Port-#7875-QueueSourceSpec
Mar 23, 2026
Merged

[1.5] Port #7859 and #7875 to fix UnfoldResourceAsyncSourceSpec#8123
Arkatufus merged 3 commits into
akkadotnet:v1.5from
Arkatufus:1.5/Port-#7875-QueueSourceSpec

Conversation

@Arkatufus

Copy link
Copy Markdown
Contributor

Aaronontheweb and others added 3 commits March 23, 2026 19:43
…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)
@Arkatufus Arkatufus merged commit 463b387 into akkadotnet:v1.5 Mar 23, 2026
11 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.

2 participants