Uh oh!
There was an error while loading. Please reload this page.
Save async contexts for ValueTask methods - #129890
Conversation
We were not properly saving/restoring async contexts for ValueTask methods because of an incorrect flag check.
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
There was a problem hiding this comment.
Pull request overview
This PR fixes Runtime Async’s ExecutionContext save/restore behavior for ValueTask-returning async variants by correcting an overly strict async-flag check in the VM. It also adds/updates tests to cover the regression and re-enables a previously skipped System.Net.Http diagnostics test.
Changes:
- Fix VM async-flag logic to treat ValueTask async variants as requiring async-context save/restore.
- Add an ExecutionContext regression test covering
async ValueTaskflows and re-enable the affected diagnostics functional test. - Add DEBUG-only JIT knobs to selectively enable/break on await-optimization by hash range.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/tests/async/execution-context/execution-context.cs | Adds a new ValueTask-focused ExecutionContext regression test. |
| src/libraries/System.Net.Http/tests/FunctionalTests/DiagnosticsTests.cs | Removes ActiveIssue to re-enable the diagnostics test previously associated with the bug. |
| src/coreclr/vm/method.hpp | Fixes async-flag check for ValueTask variants; adds operator~ helper for flag masking. |
| src/coreclr/jit/jitconfigvalues.h | Introduces DEBUG-only config entries for await optimization range/break. |
| src/coreclr/jit/importer.cpp | Adds an await-level “optimize or not” check (DEBUG-configurable) when selecting async variants. |
| src/coreclr/jit/compiler.h | Declares the new importer helper (impCheckOptimizeAwait). |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
jakobbotsch
commented
Jun 26, 2026
PTAL @VSadov |
Uh oh!
There was an error while loading. Please reload this page.
We were not properly saving/restoring async contexts for ValueTask methods because of an incorrect flag check. Fix#129771 Also add a mechanism to allow a bisection-like search of optimized awaits in the JIT. This is a surprising bug/test hole. It is also surprising that it was exposed by #128384, but the test seems to be timing sensitive -- it also stops reproducing if I introduce an `await Task.Yield()` in `WaitForConnectionWithTelemetryAsync`.
We were not properly saving/restoring async contexts for ValueTask methods because of an incorrect flag check.
Fix#129771
Also add a mechanism to allow a bisection-like search of optimized awaits in the JIT.
This is a surprising bug/test hole. It is also surprising that it was exposed by #128384, but the test seems to be timing sensitive -- it also stops reproducing if I introduce an
await Task.Yield()inWaitForConnectionWithTelemetryAsync.