Skip to content

[Runtime Async] do not hold to continuation state when completing reusable valuetask sources#124491

Merged
VSadov merged 1 commit intodotnet:mainfrom
VSadov:noHoldInVTS
Feb 17, 2026
Merged

[Runtime Async] do not hold to continuation state when completing reusable valuetask sources#124491
VSadov merged 1 commit intodotnet:mainfrom
VSadov:noHoldInVTS

Conversation

@VSadov
Copy link
Member

@VSadov VSadov commented Feb 17, 2026

Not exactly in the Runtime Async implementation, but the issue was found while testing Runtime Async in Libraries.

There is a scenario where ValueTaskSource upon completion invokes stashed {_continuation, _continuationState}. It is a one-shot invocation. Neither of {_continuation, _continuationState} are needed after that. However, while we naturally unroot _continuation by replacing it with a sentinel, the _continuationState will stay rooted until the VTS is reused.

As a result, if continuation expects that some state (like Http3ReadStream) gets finalized, it may not see that no matter how long it waits/checks/retries.

The retention was observable in intermittent failures in:

System.Net.Http.Functional.Tests.SocketsHttpHandler_HttpClientHandler_Finalization_Http3.IncompleteResponseStream_ResponseDropped_CancelsRequestToServer

(scenario may depend on mutual timings between Server and Client and whether sync/async paths are taken)

The whole purpose of the test is to see that if client drops the connection on the floor, it becomes unreachable reasonably soon and Finalization logic closes the connection.

What we see instead is the test waits for a long time and eventually times out.

A similar code pattern was observed in Threading/Channels/AsyncOperation.
Although I did not see any failures due to that, I applied the same fix of zeroing out the _continuationState before invoking the continuation.

Same applies to the _capturedContext. No need to hold to that for longer than needed.

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @agocke, @VSadov
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@jakobbotsch jakobbotsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but not my usual area of expertise.

@VSadov
Copy link
Member Author

VSadov commented Feb 17, 2026

/ba-g mono interpreter failure is #124525

@VSadov
Copy link
Member Author

VSadov commented Feb 17, 2026

LGTM, but not my usual area of expertise.

It is a fairly trivial change. If we do not keep the continuation delegate after calling it, there is no need to keep the arguments for the call.

Thanks!!

@VSadov VSadov merged commit 49e6723 into dotnet:main Feb 17, 2026
170 of 172 checks passed
@VSadov VSadov deleted the noHoldInVTS branch February 17, 2026 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments