From b036252a0872cffb6e2a80148e5077d5fbd9b63c Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Wed, 23 Sep 2020 15:04:39 -0700 Subject: [PATCH] Report non-fatal errors for failed tasks See #47891 --- .../Compiler/Core/Utilities/TaskExtensions.cs | 14 +++++++------- .../Core/Utilities/TaskFactoryExtensions.cs | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/TaskExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/TaskExtensions.cs index 4d00ad5b5ae..243306701a3 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/TaskExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/TaskExtensions.cs @@ -369,7 +369,7 @@ TResult outerFunction(Task t) // This is the only place in the code where we're allowed to call ContinueWith. var nextTask = task.ContinueWith(continuationFunction, cancellationToken, continuationOptions | TaskContinuationOptions.LazyCancellation, scheduler).Unwrap(); - nextTask.ContinueWith(ReportFatalError, continuationFunction, + nextTask.ContinueWith(ReportNonFatalError, continuationFunction, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default); @@ -412,7 +412,7 @@ TResult outerFunction(Task t) // the behavior we want. // This is the only place in the code where we're allowed to call ContinueWith. var nextTask = task.ContinueWith(continuationFunction, cancellationToken, continuationOptions | TaskContinuationOptions.LazyCancellation, scheduler).Unwrap(); - ReportFatalError(nextTask, continuationFunction); + ReportNonFatalError(nextTask, continuationFunction); return nextTask; } @@ -451,7 +451,7 @@ TResult outerFunction(Task t) // the behavior we want. // This is the only place in the code where we're allowed to call ContinueWith. var nextTask = task.ContinueWith(continuationFunction, cancellationToken, continuationOptions | TaskContinuationOptions.LazyCancellation, scheduler).Unwrap(); - ReportFatalError(nextTask, continuationFunction); + ReportNonFatalError(nextTask, continuationFunction); return nextTask; } @@ -536,16 +536,16 @@ TResult outerFunction(Task t) cancellationToken, taskContinuationOptions, scheduler).Unwrap(); } - internal static void ReportFatalError(Task task, object continuationFunction) + internal static void ReportNonFatalError(Task task, object continuationFunction) { - task.ContinueWith(ReportFatalErrorWorker, continuationFunction, + task.ContinueWith(ReportNonFatalErrorWorker, continuationFunction, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default); } [MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)] - private static void ReportFatalErrorWorker(Task task, object continuationFunction) + private static void ReportNonFatalErrorWorker(Task task, object continuationFunction) { var exception = task.Exception; var methodInfo = ((Delegate)continuationFunction).GetMethodInfo(); @@ -558,7 +558,7 @@ private static void ReportFatalErrorWorker(Task task, object continuationFunctio // ... // > ~67s // switch to thread 67 // > !dso // dump stack objects - FatalError.Report(exception); + FatalError.ReportWithoutCrash(exception); } public static Task ReportNonFatalErrorAsync(this Task task) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/TaskFactoryExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/TaskFactoryExtensions.cs index 6e13a29b4ea..c3f8e4ba739 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/TaskFactoryExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/TaskFactoryExtensions.cs @@ -55,7 +55,7 @@ public static Task SafeStartNewFromAsync(this TaskFactory factory, Func ac { // The one and only place we can call StartNew<>(). var task = factory.StartNew(actionAsync, cancellationToken, TaskCreationOptions.None, scheduler).Unwrap(); - TaskExtensions.ReportFatalError(task, actionAsync); + TaskExtensions.ReportNonFatalError(task, actionAsync); return task; } @@ -63,7 +63,7 @@ public static Task SafeStartNewFromAsync(this TaskFactory fact { // The one and only place we can call StartNew<>(). var task = factory.StartNew(funcAsync, cancellationToken, TaskCreationOptions.None, scheduler).Unwrap(); - TaskExtensions.ReportFatalError(task, funcAsync); + TaskExtensions.ReportNonFatalError(task, funcAsync); return task; } } -- GitLab