提交 8208989d 编写于 作者: M Manish Vasani

Guard against an NRE in GetAnalyzerDriverAsync when cancellation has been requested

Fixes VSO Watson #187814
上级 b5021c44
......@@ -626,40 +626,28 @@ private async Task ComputeAnalyzerDiagnosticsAsync(AnalysisScope analysisScope,
private async Task<AnalyzerDriver> GetAnalyzerDriverAsync(CancellationToken cancellationToken)
{
try
{
cancellationToken.ThrowIfCancellationRequested();
cancellationToken.ThrowIfCancellationRequested();
// Get instance of analyzer driver from the driver pool.
AnalyzerDriver driver = _driverPool.Allocate();
// Get instance of analyzer driver from the driver pool.
AnalyzerDriver driver = _driverPool.Allocate();
try
try
{
// Start the initialization task, if required.
if (driver.WhenInitializedTask == null)
{
// Start the initialization task, if required.
if (driver.WhenInitializedTask == null)
{
driver.Initialize(_compilation, _analysisOptions, _compilationData, categorizeDiagnostics: true, cancellationToken: cancellationToken);
}
// Wait for driver initialization to complete: this executes the Initialize and CompilationStartActions to compute all registered actions per-analyzer.
await driver.WhenInitializedTask.ConfigureAwait(false);
}
finally
{
if (driver.WhenInitializedTask.IsCanceled)
{
// If the initialization task was cancelled, we retry again with our own cancellation token.
// This can happen if the task that started the initialization was cancelled by the callee, and the new request picked up this driver instance.
_driverPool.ForgetTrackedObject(driver);
driver = await GetAnalyzerDriverAsync(cancellationToken).ConfigureAwait(false);
}
driver.Initialize(_compilation, _analysisOptions, _compilationData, categorizeDiagnostics: true, cancellationToken: cancellationToken);
}
// Wait for driver initialization to complete: this executes the Initialize and CompilationStartActions to compute all registered actions per-analyzer.
await driver.WhenInitializedTask.ConfigureAwait(false);
return driver;
}
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
catch (OperationCanceledException)
{
throw ExceptionUtilities.Unreachable;
FreeDriver(driver);
throw;
}
}
......@@ -667,7 +655,8 @@ private void FreeDriver(AnalyzerDriver driver)
{
if (driver != null)
{
if (driver.WhenInitializedTask.IsCanceled)
// Throw away the driver instance if the initialization didn't succeed.
if (driver.WhenInitializedTask == null || driver.WhenInitializedTask.IsCanceled)
{
_driverPool.ForgetTrackedObject(driver);
}
......@@ -1032,9 +1021,16 @@ public async Task<AnalyzerTelemetryInfo> GetAnalyzerTelemetryInfoAsync(Diagnosti
{
VerifyAnalyzerArgument(analyzer);
var actionCounts = await GetAnalyzerActionCountsAsync(analyzer, cancellationToken).ConfigureAwait(false);
var executionTime = GetAnalyzerExecutionTime(analyzer);
return new AnalyzerTelemetryInfo(actionCounts, executionTime);
try
{
var actionCounts = await GetAnalyzerActionCountsAsync(analyzer, cancellationToken).ConfigureAwait(false);
var executionTime = GetAnalyzerExecutionTime(analyzer);
return new AnalyzerTelemetryInfo(actionCounts, executionTime);
}
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
{
throw ExceptionUtilities.Unreachable;
}
}
/// <summary>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册