Fix cancellation handling in Parallel.For#48056
Merged
sharwell merged 2 commits intodotnet:masterfrom Sep 28, 2020
Merged
Conversation
333fred
approved these changes
Sep 25, 2020
Contributor
Author
|
@dotnet/roslyn-compiler for a second review |
jaredpar
reviewed
Sep 25, 2020
sharwell
commented
Sep 25, 2020
src/Compilers/CSharp/Portable/Symbols/Source/SourceNamespaceSymbol_Completion.cs
Outdated
Show resolved
Hide resolved
This change ensures that cancellation exceptions that get wrapped in an AggregateException are treated as cancellation instead of failure.
dfa9711 to
89567d8
Compare
CyrusNajmabadi
approved these changes
Sep 26, 2020
jaredpar
approved these changes
Sep 28, 2020
| catch (OperationCanceledException e) when (cancellationToken.IsCancellationRequested && e.CancellationToken != cancellationToken) | ||
| { | ||
| // Parallel.For checks for a specific cancellation token, so make sure we throw with the | ||
| // correct one. |
Member
There was a problem hiding this comment.
Curious: how did you discover this behavior? If there is a doc you read may be helpful to link to it here for future readers to find.
Contributor
Author
There was a problem hiding this comment.
I looked at referencesource.microsoft.com after observing a test failure.
Contributor
Author
Contributor
Author
There was a problem hiding this comment.
IMO this policy is slightly too aggressive. The API would be easier to use if it supported inner cancellation exceptions with any cancellation token provided the one passed in the parallel options was also cancelled. But we just don't use these APIs enough to figure out all the details on that.
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.
This change ensures that cancellation exceptions that get wrapped in an
AggregateExceptionare treated as cancellation instead of failure.This fixes the error that resulted in a failure of
NotNullIfNotNull_Return_DuplicateParametersin Pipelines - Run 20200925.9 (azure.com).