From dff8c027190ca8355f67eb12a3c098515054af1f Mon Sep 17 00:00:00 2001 From: Manish Vasani Date: Fri, 1 Feb 2019 16:09:46 -0800 Subject: [PATCH] Handle null reference exception during analyzer execution when cancellation has been requested Fixes VSO Watson [#763828](https://devdiv.visualstudio.com/DevDiv/_workitems/edit/763828) All the dumps for the watson show that cancellation was requested during analysis, leading to one thread clearing state while other thread faulted. --- .../Core/Portable/DiagnosticAnalyzer/AnalyzerDriver.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerDriver.cs b/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerDriver.cs index 89060a9af3a..8f2e44f97b1 100644 --- a/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerDriver.cs +++ b/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerDriver.cs @@ -1853,6 +1853,11 @@ private static void ComputeDeclarationsInNode(SemanticModel semanticModel, ISymb // Mark completion if we successfully executed all actions and only if we are analyzing a span containing the entire syntax node. if (success && analysisStateOpt != null && !declarationAnalysisData.IsPartialAnalysis) { + // Ensure that we do not mark declaration complete/clear state if cancellation was requested. + // Other thread(s) might still be executing analysis, and clearing state could lead to corrupt execution + // or unknown exceptions. + cancellationToken.ThrowIfCancellationRequested(); + foreach (var analyzer in analysisScope.Analyzers) { analysisStateOpt.MarkDeclarationComplete(symbol, declarationIndex, analyzer); -- GitLab