[release/11.0] Fix double monitor release in synchronized runtime-async methods - #133935
Merged
Merged
Conversation
…#133866) Awaiting a faulted awaitable returned by a synchronized method can release the monitor twice, replacing the original exception or releasing a caller-owned recursive acquisition. - **JIT:** Clear `lvaMonAcquired` immediately after the importer-generated monitor exit, preventing a subsequent await exception from triggering another release. The released-state value is `0`; `1` means acquired. - **Regression coverage:** Extend the existing `Task` and `ValueTask` tests to verify exception identity and monitor ownership, with and without a caller-held lock. Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jakobbotsch <7887810+jakobbotsch@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @agocke |
This was referenced Sep 15, 2026
EgorBo
approved these changes
Sep 15, 2026
Member
|
/ba-g known issues. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #133866 to release/11.0
/cc @jakobbotsch @copilot
Customer Impact
Awaiting a synchronized task-returning method that throws from a runtime async method results in double releasing the synchronized lock, throwing the wrong exception to the consumer.
For example, in .NET 11, the following code throws
System.Threading.SynchronizationLockExceptioninstead ofSystem.Threading.Tasks.TaskCanceledExceptionif compiled with runtime async:Regression
Introduced by async version work in #129901
Testing
Unit test added.
Risk
Low.