Skip to content

[release/11.0] Fix double monitor release in synchronized runtime-async methods - #133935

Merged
JulieLeeMSFT merged 1 commit into
release/11.0from
backport/pr-133866-to-release/11.0
Sep 15, 2026
Merged

JulieLeeMSFT merged 1 commit into
release/11.0from
backport/pr-133866-to-release/11.0

Conversation

@github-actions

@github-actions github-actions Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Backport of #133866 to release/11.0

/cc @jakobbotsch @copilot

Customer Impact

  • Customer reported
  • Found internally

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.SynchronizationLockException instead of System.Threading.Tasks.TaskCanceledException if compiled with runtime async:

using StreamWriter sw = new StreamWriter(new MemoryStream());
var sb = new StringBuilder();
await TextWriter.Synchronized(sw).WriteLineAsync(sb, new CancellationToken(canceled: true));

Regression

  • Yes
  • No

Introduced by async version work in #129901

Testing

Unit test added.

Risk

Low.

…#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

Copy link
Copy Markdown
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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@JulieLeeMSFT

Copy link
Copy Markdown
Member

/ba-g known issues.

@JulieLeeMSFT JulieLeeMSFT added the Servicing-approved Approved for servicing release label Sep 15, 2026
@JulieLeeMSFT JulieLeeMSFT added this to the 11.0.0 milestone Sep 15, 2026
@JulieLeeMSFT
JulieLeeMSFT merged commit 1bc9347 into release/11.0 Sep 15, 2026
117 of 120 checks passed
@JulieLeeMSFT
JulieLeeMSFT deleted the backport/pr-133866-to-release/11.0 branch September 15, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-VM-coreclr Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants