问题描述
我运行Owin Selfhost基础的WebAPI在那里我已经通过
放在一个API未处理的异常记录 config.Services.Add(typeof运算(IExceptionLogger),_apiExceptionLogger);
ApiExceptionLogger的相关部分:
公共覆盖无效日志(ExceptionLoggerContext上下文)
{
如果(背景== NULL || context.ExceptionContext == NULL)回报;
Logger.Error(从网络API未处理的异常,context.ExceptionContext.Exception);
}
的情况下,它捕捉和记录经常是那些在客户端请求数据集,然后,而结果(JSON)被送回关闭连接 - 人民作出的镀铬的请求,然后将所有结果之前击中X按钮回来:P
我粘贴下面的完整堆栈跟踪,只是想知道两件事情:
- 这是常规的/预期的行为? AFAIK这是...我快pretty的默认API和流水线
- 有什么办法来处理呢?从本质上更优雅停止请求处理的情况下,取消(整个请求管道穿插的取消标记就浮现在脑海中,但并不像他们做很多在这种情况下,之后的所有令牌仅支持合作社注销)
我没有做过的事件发生在套接字级别的序列中的任何深潜,到目前为止,这仅仅是一个记录滋扰。
System.Net.Http.Htt prequestException:错误,同时复制内容流。 ---> System.IO.IOException ---> System.Net.HttpListenerException:在I / O操作已中止,因为一个线程退出或应用程序请求
在System.Net.Htt presponseStream.EndWrite(IAsyncResult的asyncResult)
在Microsoft.Owin.Host.HttpListener.RequestProcessing.ExceptionFilterStream.EndWrite(IAsyncResult的asyncResult)
---内部异常堆栈跟踪的结尾---
在Microsoft.Owin.Host.HttpListener.RequestProcessing.ExceptionFilterStream.EndWrite(IAsyncResult的asyncResult)
在System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult的IAR,Func`2的endfunction,Action`1 endAction,Task`1承诺,布尔requiresSynchronization)
---内部异常堆栈跟踪的结尾---
在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务的任务)
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务的任务)
在System.Web.Http.Owin.HttpMessageHandlerAdapter< SendResponseContentAsync> d__20.MoveNext()在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务的任务)
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务的任务)
在System.Web.Http.Owin.HttpMessageHandlerAdapter< SendResponseContentAsync> d__20.MoveNext()
我对树莓派Owin主机类似的问题。这可能有助于http://stackoverflow.com/a/30583109/1786034
I'm running an Owin Selfhost based WebApi where i've put in an API unhandled exception logger via
config.Services.Add(typeof(IExceptionLogger), _apiExceptionLogger);
Relevant part of ApiExceptionLogger:
public override void Log(ExceptionLoggerContext context)
{
if (context == null || context.ExceptionContext == null) return;
Logger.Error("Unhandled exception from Web API", context.ExceptionContext.Exception);
}
The cases it's catching and logging regularly are ones where the client requests a dataset and then closes the connection while the results (JSON) are being sent back - people making a request in chrome, and then hitting the X button before all results come back :P
I've pasted a stacktrace below for completeness, just want to know two things:
- Is this regular/expected behavior? AFAIK it is...I'm running a pretty default API and pipeline
- Is there any way to handle this? Essentially stop request processing more gracefully in case of a cancellation (the cancellation tokens peppered throughout the request pipeline do come to mind, but doesn't look like they do much in this case, after all the tokens only support co-operative cancellation)
I haven't done any deep dive on the sequence of events happening at the socket level, so far this is only a logging nuisance.
System.Net.Http.HttpRequestException: Error while copying content to a stream. ---> System.IO.IOException ---> System.Net.HttpListenerException: The I/O operation has been aborted because of either a thread exit or an application request
at System.Net.HttpResponseStream.EndWrite(IAsyncResult asyncResult)
at Microsoft.Owin.Host.HttpListener.RequestProcessing.ExceptionFilterStream.EndWrite(IAsyncResult asyncResult)
--- End of inner exception stack trace ---
at Microsoft.Owin.Host.HttpListener.RequestProcessing.ExceptionFilterStream.EndWrite(IAsyncResult asyncResult)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of inner exception stack trace ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Owin.HttpMessageHandlerAdapter.<SendResponseContentAsync>d__20.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Owin.HttpMessageHandlerAdapter.<SendResponseContentAsync>d__20.MoveNext()
I had a similar issue with Owin host on Raspberry Pi. This may help http://stackoverflow.com/a/30583109/1786034
这篇关于Owin SelfHost的WebAPI - 客户端的响应时关闭连接抛出一个例外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!