Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OperationCanceledException from System.Web.Http.HostAuthenticationFilter

We were recently checking our error logs and saw lots of "The operation was canceled" exceptions. We were not able to reproduce them, looks like an aborted request, but they all come from OWIN HostAuthenticationFilter.

Here is the stack trace:

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()

Has anyone seen that error before?

like image 254
SupperSlonic Avatar asked Nov 26 '14 02:11

SupperSlonic


1 Answers

I know this question is over a year old but I am leaving it here in case anyone else had the same question as I did.

Yes, this is caused by a request being cancel and could be for a number of reasons but in my case and what I suspect is your case as well. It was caused by the client when it closed the request connection before the server could respond. Thus the server cancels the no longer needed thread to free it up and throws the exception, System.OperationCanceledException.

Check out this issue on GitHub for IdentityServer which was created half a year after this StackOverflow question: https://github.com/IdentityServer/IdentityServer3/issues/1698

Yea, sounds like the user-agent closed its HTTP connection before the server had a chance to finish replying. - source

See this similar StackOverflow question for ways to catch these exceptions from being logged ASP.NET Web API OperationCanceledException when browser cancels the request.

like image 176
scraymer Avatar answered Oct 18 '22 21:10

scraymer