任务取消异常导致Web API项目中的内部服务器错误

时间:2016-06-07 19:50:26

标签: c# asp.net azure

我有一个ASP.NET Web API项目。我在Azure中托管了3个云服务,后面是流量管理器端点。最近,有一些失败,我需要一些帮助来理解根本原因。

流量高于平时,但通话工作正常。在某个特定时间窗口(大约10分钟)内,其中一个实例开始抛出内部服务器错误。甚至健康ping请求都会导致内部服务器错误。大约一两个小时成功的API调用也失败了。下面提供了堆栈跟踪。

System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()

在我看来,问题与代码无关。一种可能性是线程争用,但是当我创建一个新的测试云服务并对其进行多次并行调用时,我得到了超时但没有内部服务器错误。

更新 我们有一个请求处理程序,它类似于以下内容,似乎ASP.NET框架通过处理程序中的取消令牌触发取消。我们已经验证在执行处理程序后控件不会流向我们的控制器。

public class RequestMessageHandler : DelegatingHandler
    {
        protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                throw new ArgumentException("RequestMessage is null");
            }

            MyEventSource.Log.HttpIncomingStart(request);

            return base.SendAsync(request, cancellationToken);
        }
    }

0 个答案:

没有答案