提交 89567d8b 编写于 作者: S Sam Harwell

Fix cancellation handling in Parallel.For

This change ensures that cancellation exceptions that get wrapped in an
AggregateException are treated as cancellation instead of failure.
上级 fc6da2df
......@@ -2489,6 +2489,13 @@ internal override void GetDiagnostics(CompilationStage stage, bool includeEarlie
{
throw ExceptionUtilities.Unreachable;
}
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.
cancellationToken.ThrowIfCancellationRequested();
throw ExceptionUtilities.Unreachable;
}
}));
}
else
......
......@@ -64,6 +64,13 @@ internal override void ForceComplete(SourceLocation locationOpt, CancellationTok
{
throw ExceptionUtilities.Unreachable;
}
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.
cancellationToken.ThrowIfCancellationRequested();
throw ExceptionUtilities.Unreachable;
}
}));
foreach (var member in members)
......
......@@ -2094,6 +2094,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
builder.AddRange(SyntaxTrees(i).GetDiagnostics(cancellationToken))
Catch e As Exception When FatalError.ReportUnlessCanceled(e)
Throw ExceptionUtilities.Unreachable
Catch e As OperationCanceledException When cancellationToken.IsCancellationRequested AndAlso e.CancellationToken <> cancellationToken
' Parallel.For checks for a specific cancellation token, so make sure we throw with the
' correct one.
cancellationToken.ThrowIfCancellationRequested()
Throw ExceptionUtilities.Unreachable
End Try
End Sub))
Else
......
......@@ -625,6 +625,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
TryGetSourceFile(trees(i)).GenerateAllDeclarationErrors()
Catch e As Exception When FatalError.ReportUnlessCanceled(e)
Throw ExceptionUtilities.Unreachable
Catch e As OperationCanceledException When cancellationToken.IsCancellationRequested AndAlso e.CancellationToken <> cancellationToken
' Parallel.For checks for a specific cancellation token, so make sure we throw with the
' correct one.
cancellationToken.ThrowIfCancellationRequested()
Throw ExceptionUtilities.Unreachable
End Try
End Sub))
trees.Free()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册