System.Web.Http.HostAuthenticationFilter中的OperationCanceledException

时间:2014-11-26 02:38:41

标签: asp.net-web-api scheduled-tasks unobserved-exception

我们最近检查了我们的错误日志,看到了很多“操作被取消”的例外情况。 我们无法重现它们,看起来像是一个中止的请求,但它们都来自OWIN HostAuthenticationFilter。

这是堆栈跟踪:

System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.Web.Http.HostAuthenticationFilter.<AuthenticateAsync>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.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__24.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.Web.Http.Controllers.AuthenticationFilterResult.<ExecuteAsync>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.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()

之前有没有人见过这个错误?

1 个答案:

答案 0 :(得分:5)

我知道这个问题已经过了一年多了,但是我将它留在这里以防万一其他人和我一样有问题。

是的,这是由于请求被取消引起的,可能是出于多种原因,但在我的情况下,我怀疑你的情况也是如此。 它是由客户端在服务器响应之前关闭请求连接时引起的。因此服务器取消不再需要的线程来释放它并抛出异常System.OperationCanceledException。< / p>

在这个StackOverflow问题半年后创建的GitHub for IdentityServer上查看此问题:https://github.com/IdentityServer/IdentityServer3/issues/1698

  

是的,听起来像用户代理在服务器有机会完成回复之前关闭了它的HTTP连接。 - source

请参阅类似的StackOverflow问题,了解如何记录这些异常({3}}。