-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[RuntimeAsync] Fix for configured ValueTask sources #120704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
CC: @stephentoub Are we getting the desired behavior correctly? We do have testcases sensitive to these behaviors, which fail without this fix. |
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR addresses a scenario where ValueTask doesn't properly handle configuration of async continuations when wrapping ValueTaskSource implementations. The fix ensures that unconfigured awaits behave as if they were configured with ConfigureAwait(false) when the underlying ValueTaskSource can choose to ignore scheduling context.
Key changes:
- Introduces deferred configuration mechanism for
ValueTaskSourcecallbacks - Updates runtime async thunks to use unconfigured task conversion
- Enables runtime async tests that were previously disabled
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ValueTask.cs | Adds AsUnconfiguredTask() methods and deferred configuration support for ValueTaskSource instances |
| src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs | Implements configuration logic to handle context flags between continuations and ValueTaskSource |
| src/coreclr/vm/corelib.h | Updates method bindings to use unconfigured task conversion |
| src/coreclr/vm/asyncthunks.cpp | Changes async thunks to call AsUnconfiguredTask instead of AsTask |
| src/coreclr/inc/clrconfigvalues.h | Enables runtime async support by default |
| src/tests/async/Directory.Build.targets | Removes project build disable for runtime async tests |
| src/tests/async/Directory.Build.props | Adds warning suppression for new analyzer rule |
| src/tests/async/struct/struct.cs | Adds attributes to opt out of runtime async generation for struct methods |
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
|
@jakobbotsch @stephentoub - I have pushed the latest changes that add a directed testcase that exercise the discussed ValueTaskSource scenario a bit deeper than existing tests in Libraries do. Please take a look. |
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
jakobbotsch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM beyond the few minor pieces of feedback.
It is unfortunate with the extra layers of indirection around ValueTaskSourceNotifier, but it is probably something we can look into removing as part of #119842.
Co-authored-by: Jakob Botsch Nielsen <Jakob.botsch.nielsen@gmail.com>
Yes, #119842 might allow removing |
This reverts commit dbeac36.
Fixes: #120709
There is a scenario where
ValueTaskdecides on whether to run continuations on the scheduling context or not.It happens in a case when an
awaitcalls into aValueTaskthat wraps aValueTaskSource.In such case we may have a nontrivial context provided to the
ValueTaskSourceat the time of the await, butValueTaskSourcemay choose to ignore the context when running callbacks.A typical test sensitive to this looks like:
runtime/src/libraries/System.IO.Pipelines/tests/SchedulerFacts.cs
Lines 48 to 89 in ce717ac
The part
should behave as
Otherwise we end up posting the
doReadcontinuation to the trackingCustomSynchronizationContextwhich only tracks Posts and does not run them, thus the test makes no progress.