[RuntimeAsync] When async method throws OperationCanceledException, its thunk should produce a Canceled task#120346
Merged
VSadov merged 9 commits intodotnet:mainfrom Oct 7, 2025
Merged
Conversation
Contributor
|
Tagging subscribers to this area: @mangod9 |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR implements proper cancellation handling for async methods in the runtime async feature. When an async method throws OperationCanceledException, the task-returning thunk should now produce a Canceled task instead of a Faulted task, which better aligns with caller expectations and prevents unhandled exceptions.
Key changes:
- Modified task finalization methods to accept both continuation and exception parameters
- Added logic to distinguish between cancellation and other exceptions when creating task results
- Added comprehensive test coverage for the cancellation behavior
- Enabled runtime async testing infrastructure
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/tests/async/struct/struct.cs |
Added opt-out attributes for async methods in structs |
src/tests/async/cancellation/cancellation.csproj |
New test project configuration file |
src/tests/async/cancellation/cancellation.cs |
New test file verifying cancellation behavior for Task and ValueTask |
src/tests/async/Directory.Build.targets |
Removed global disable flag to enable async testing |
src/tests/async/Directory.Build.props |
Added warning suppression for SYSLIB5007 |
src/coreclr/vm/metasig.h |
Updated method signatures to include exception parameter |
src/coreclr/vm/corelib.h |
Updated finalization method signatures |
src/coreclr/vm/binder.cpp |
Fixed generic signature processing order |
src/coreclr/vm/asyncthunks.cpp |
Enhanced thunk generation with exception handling |
src/coreclr/inc/clrconfigvalues.h |
Enabled runtime async by default |
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs |
Implemented cancellation-aware task finalization |
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
VSadov
commented
Oct 3, 2025
jakobbotsch
reviewed
Oct 3, 2025
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
jakobbotsch
reviewed
Oct 3, 2025
jakobbotsch
approved these changes
Oct 7, 2025
This reverts commit 8cf79ab.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes: #120344
Producing Faulted task instead of Canceled may be unexpected by the caller and result in unhandled exceptions.