提交 b036252a 编写于 作者: S Sam Harwell

Report non-fatal errors for failed tasks

See #47891
上级 8d877410
...@@ -369,7 +369,7 @@ TResult outerFunction(Task t) ...@@ -369,7 +369,7 @@ TResult outerFunction(Task t)
// This is the only place in the code where we're allowed to call ContinueWith. // 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(); var nextTask = task.ContinueWith(continuationFunction, cancellationToken, continuationOptions | TaskContinuationOptions.LazyCancellation, scheduler).Unwrap();
nextTask.ContinueWith(ReportFatalError, continuationFunction, nextTask.ContinueWith(ReportNonFatalError, continuationFunction,
CancellationToken.None, CancellationToken.None,
TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously, TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously,
TaskScheduler.Default); TaskScheduler.Default);
...@@ -412,7 +412,7 @@ TResult outerFunction(Task t) ...@@ -412,7 +412,7 @@ TResult outerFunction(Task t)
// the behavior we want. // the behavior we want.
// This is the only place in the code where we're allowed to call ContinueWith. // 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(); var nextTask = task.ContinueWith(continuationFunction, cancellationToken, continuationOptions | TaskContinuationOptions.LazyCancellation, scheduler).Unwrap();
ReportFatalError(nextTask, continuationFunction); ReportNonFatalError(nextTask, continuationFunction);
return nextTask; return nextTask;
} }
...@@ -451,7 +451,7 @@ TResult outerFunction(Task t) ...@@ -451,7 +451,7 @@ TResult outerFunction(Task t)
// the behavior we want. // the behavior we want.
// This is the only place in the code where we're allowed to call ContinueWith. // 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(); var nextTask = task.ContinueWith(continuationFunction, cancellationToken, continuationOptions | TaskContinuationOptions.LazyCancellation, scheduler).Unwrap();
ReportFatalError(nextTask, continuationFunction); ReportNonFatalError(nextTask, continuationFunction);
return nextTask; return nextTask;
} }
...@@ -536,16 +536,16 @@ TResult outerFunction(Task t) ...@@ -536,16 +536,16 @@ TResult outerFunction(Task t)
cancellationToken, taskContinuationOptions, scheduler).Unwrap(); 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, CancellationToken.None,
TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously, TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously,
TaskScheduler.Default); TaskScheduler.Default);
} }
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)] [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 exception = task.Exception;
var methodInfo = ((Delegate)continuationFunction).GetMethodInfo(); var methodInfo = ((Delegate)continuationFunction).GetMethodInfo();
...@@ -558,7 +558,7 @@ private static void ReportFatalErrorWorker(Task task, object continuationFunctio ...@@ -558,7 +558,7 @@ private static void ReportFatalErrorWorker(Task task, object continuationFunctio
// ... // ...
// > ~67s // switch to thread 67 // > ~67s // switch to thread 67
// > !dso // dump stack objects // > !dso // dump stack objects
FatalError.Report(exception); FatalError.ReportWithoutCrash(exception);
} }
public static Task ReportNonFatalErrorAsync(this Task task) public static Task ReportNonFatalErrorAsync(this Task task)
......
...@@ -55,7 +55,7 @@ public static Task SafeStartNewFromAsync(this TaskFactory factory, Func<Task> ac ...@@ -55,7 +55,7 @@ public static Task SafeStartNewFromAsync(this TaskFactory factory, Func<Task> ac
{ {
// The one and only place we can call StartNew<>(). // The one and only place we can call StartNew<>().
var task = factory.StartNew(actionAsync, cancellationToken, TaskCreationOptions.None, scheduler).Unwrap(); var task = factory.StartNew(actionAsync, cancellationToken, TaskCreationOptions.None, scheduler).Unwrap();
TaskExtensions.ReportFatalError(task, actionAsync); TaskExtensions.ReportNonFatalError(task, actionAsync);
return task; return task;
} }
...@@ -63,7 +63,7 @@ public static Task<TResult> SafeStartNewFromAsync<TResult>(this TaskFactory fact ...@@ -63,7 +63,7 @@ public static Task<TResult> SafeStartNewFromAsync<TResult>(this TaskFactory fact
{ {
// The one and only place we can call StartNew<>(). // The one and only place we can call StartNew<>().
var task = factory.StartNew(funcAsync, cancellationToken, TaskCreationOptions.None, scheduler).Unwrap(); var task = factory.StartNew(funcAsync, cancellationToken, TaskCreationOptions.None, scheduler).Unwrap();
TaskExtensions.ReportFatalError(task, funcAsync); TaskExtensions.ReportNonFatalError(task, funcAsync);
return task; return task;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册