提交 63fa06b1 编写于 作者: M Manish Vasani

Fix intermittent crash in CompilationWithAnalyzers due to an OjbectDisposedException.

Fixes VSO Bug [199252](https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems?_a=edit&id=199252)

Root cause: We were attempting to access the cancellation token for a cancellation token source within a lambda within the using statement for the token source. If client fires a cancellation before the task within the lambda executes, the token source may have been disposed when the task is eventually activated.

Fix: This change saves the cancellation token for the token source upfront for use within the lambda and also checks for cancellation before computing diagnostics.

Justification for ask mode: We are hitting this intermittent crash in perf runs in an internal VSO branch and fix doesn't have any risks.
上级 3b6ea89f
...@@ -559,6 +559,9 @@ private async Task ComputeAnalyzerDiagnosticsAsync(AnalysisScope analysisScope, ...@@ -559,6 +559,9 @@ private async Task ComputeAnalyzerDiagnosticsAsync(AnalysisScope analysisScope,
{ {
try try
{ {
// Fetch the cancellation token here to avoid capturing linkedCts in the getComputeTask lambda as the task may run after linkedCts has been disposed due to cancellation.
var linkedCancellationToken = linkedCts.Token;
// Core task to compute analyzer diagnostics. // Core task to compute analyzer diagnostics.
Func<Tuple<Task, CancellationTokenSource>> getComputeTask = () => Tuple.Create( Func<Tuple<Task, CancellationTokenSource>> getComputeTask = () => Tuple.Create(
Task.Run(async () => Task.Run(async () =>
...@@ -571,8 +574,10 @@ private async Task ComputeAnalyzerDiagnosticsAsync(AnalysisScope analysisScope, ...@@ -571,8 +574,10 @@ private async Task ComputeAnalyzerDiagnosticsAsync(AnalysisScope analysisScope,
// Get event queue with pending events to analyze. // Get event queue with pending events to analyze.
eventQueue = getEventQueue(); eventQueue = getEventQueue();
linkedCancellationToken.ThrowIfCancellationRequested();
// Execute analyzer driver on the given analysis scope with the given event queue. // Execute analyzer driver on the given analysis scope with the given event queue.
await ComputeAnalyzerDiagnosticsCoreAsync(driver, eventQueue, analysisScope, cancellationToken: linkedCts.Token).ConfigureAwait(false); await ComputeAnalyzerDiagnosticsCoreAsync(driver, eventQueue, analysisScope, cancellationToken: linkedCancellationToken).ConfigureAwait(false);
} }
finally finally
{ {
...@@ -584,7 +589,7 @@ private async Task ComputeAnalyzerDiagnosticsAsync(AnalysisScope analysisScope, ...@@ -584,7 +589,7 @@ private async Task ComputeAnalyzerDiagnosticsAsync(AnalysisScope analysisScope,
throw ExceptionUtilities.Unreachable; throw ExceptionUtilities.Unreachable;
} }
}, },
linkedCts.Token), linkedCancellationToken),
cts); cts);
// Wait for higher priority tree document tasks to complete. // Wait for higher priority tree document tasks to complete.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册