Skip to content

Do not synchronize async return-dropping thunks - #137050

Merged
MichalStrehovsky merged 1 commit into
mainfrom
fix/async-return-dropping-thunk-synchronization
Nov 11, 2026
Merged

MichalStrehovsky merged 1 commit into
mainfrom
fix/async-return-dropping-thunk-synchronization

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member

Summary

Follow up on #132425 (comment) for the existing Task-to-Task return-dropping thunks.

  • Clear miSynchronized on CoreCLR's synthesized return-dropping async variant.
  • Override ReturnDroppingAsyncThunk.IsSynchronized to return false in NativeAOT.
  • Keep synchronization on the actual implementation, rather than acquiring the receiver's monitor again in the adapter and retaining that acquisition across suspension.
  • Add regression coverage to async/covariant-return for a synchronized covariant override returning a pending task and an unsynchronized further override. Check that the implementation sees the expected monitor state and that another thread can acquire the receiver's monitor while the call is suspended.

The regression project is enabled for both CoreCLR and NativeAOT.

Validation

  • Built the CoreCLR Release native components and matching CoreLib.
  • Built ILCompiler.Compiler in Release.
  • Built the full covariant-return and custom-task-covariant-return regression projects against the SDK reference assemblies.
  • Reproduced the pending-task monitor regression on the unmodified SDK runtime.
  • Executed assertions using the rebuilt NativeAOT compiler's actual method descriptors: the original method and its regular async variant remain synchronized, while the return-dropping thunk is unsynchronized and returns void.

Full test execution on the rebuilt CoreCLR is blocked by a startup SIGSEGV before test entry, at the unmanaged-callers-only entry point for AppContext.Setup. Rebuilding with methodtablebuilder.cpp restored to unchanged main produces the same startup failure. Full NativeAOT execution was not run.

Keep monitor acquisition on the target implementation in CoreCLR and NativeAOT. Add pending-task and unsynchronized further-override regression coverage.

Co-authored-by: Copilot <[email protected]>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

End-to-end monitor behavior across async suspension remains unvalidated on both rebuilt runtimes: a reported CoreCLR startup crash blocks testing, and NativeAOT validation covered descriptors without executing the regression.

No open issues 🎉

What changed in this PR

This PR keeps synchronization on the actual method implementation, preventing async return-dropping adapters from retaining the receiver’s monitor across suspension in CoreCLR and NativeAOT.

Changes:

  • Clear synchronization on CoreCLR’s synthesized return-dropping async variant.
  • Mark NativeAOT’s return-dropping thunk as unsynchronized.
  • Add regression coverage for synchronized and further unsynchronized overrides, checking monitor ownership and availability while awaiting a pending task.
File Description
src/​tests/​async/​covariant-return/​covariant-returns.cs Add pending-task regression tests for monitor behavior across covariant overrides.
src/​coreclr/​vm/​methodtablebuilder.cpp Clear miSynchronized on return-dropping async variants.
src/​coreclr/​tools/​Common/​Compiler/​AsyncMethodVariant.cs Override ReturnDroppingAsyncThunk.IsSynchronized to return false.

Review effort: Balanced

@MichalStrehovsky

Copy link
Copy Markdown
Member Author

@VSadov copilot pointed this out in the new code of #132425 but the same problem exists elsewhere, this fixes it.

@VSadov

VSadov commented Nov 10, 2026

Copy link
Copy Markdown
Member

@VSadov copilot pointed this out in the new code of #132425 but the same problem exists elsewhere, this fixes it.

When I sked it to check if we have similar issue with synchronized methods and other thunks, nothing was found and I assumed that return dropping thunks are somehow immune to this.

Thanks for fixing this!

@VSadov VSadov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@MichalStrehovsky
MichalStrehovsky merged commit 3753139 into main Nov 11, 2026
111 checks passed
@MichalStrehovsky
MichalStrehovsky deleted the fix/async-return-dropping-thunk-synchronization branch November 11, 2026 02:01
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 11, 2026
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.

3 participants