14

我们最近检查了我们的错误日志,看到了很多“操作被取消”的异常。我们无法重现它们,看起来像是一个中止的请求,但它们都来自 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()

有没有人见过这个错误?

4

1 回答 1

10

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

是的,这是由取消请求引起的,可能有多种原因,但就我而言,我怀疑您的情况也是如此。它是由客户端在服务器响应之前关闭请求连接引起的。因此,服务器取消不再需要的线程以释放它并抛出异常,System.OperationCanceledException.

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

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

有关在浏览器取消请求时从记录 ASP.NET Web API OperationCanceledException 中捕获这些异常的方法,请参阅这个类似的 StackOverflow 问题。

于 2016-02-12T15:20:02.267 回答