Skip to content

Conversation

@VSadov
Copy link
Member

@VSadov VSadov commented Nov 8, 2025

Fixes: #121459

The wrapped continuation is expected to be used only once - when the corresponding async method is resumed. We can and should null-out the continuation while fetching it in the dispatcher. There is no need to keep it referenced from the task once fetched as it may cause "leaks" observable via WeakReference/Finalization and the like.

The close analog of this behavior in the async1 is the C# state machine zeroing out pointer-containing fields in the display struct upon completing or faulting the task.

https://github.com/dotnet/roslyn/blob/f2df0ad6d3ef30ed033a794e7150a5600be50a95/src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/AsyncMethodToStateMachineRewriter.cs#L186

https://github.com/dotnet/roslyn/blob/f2df0ad6d3ef30ed033a794e7150a5600be50a95/src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/AsyncMethodToStateMachineRewriter.cs#L224

Copilot AI review requested due to automatic review settings November 8, 2025 02:38
@VSadov VSadov requested review from jakobbotsch and removed request for Copilot November 8, 2025 02:39
@dotnet-policy-service
Copy link
Contributor

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

Copilot AI review requested due to automatic review settings November 8, 2025 19:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the continuation state management in async task operations to use move semantics, improving code clarity and adding defensive checks.

  • Renames GetContinuationState to MoveContinuationState to reflect that the method now transfers ownership
  • Implements move semantics by clearing m_stateObject after retrieval
  • Adds Debug.Assert checks to verify m_stateObject is null before setting new values

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.

[RuntimeAsync] Test failure in NonDisposedSocket_SafeHandlesCollected with runtime async enabled.

2 participants