Repository navigation
Do not synchronize async return-dropping thunks - #137050
Conversation
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: 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. |
There was a problem hiding this comment.
🔵 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
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! |
Summary
Follow up on #132425 (comment) for the existing Task-to-Task return-dropping thunks.
miSynchronizedon CoreCLR's synthesized return-dropping async variant.ReturnDroppingAsyncThunk.IsSynchronizedto returnfalsein NativeAOT.async/covariant-returnfor 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
ILCompiler.Compilerin Release.covariant-returnandcustom-task-covariant-returnregression projects against the SDK reference assemblies.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 withmethodtablebuilder.cpprestored to unchangedmainproduces the same startup failure. Full NativeAOT execution was not run.