我正在运行基于Owin Selfhost的WebApi,我已经通过
输入了API未处理的异常记录器config.Services.Add(typeof(IExceptionLogger), _apiExceptionLogger);
ApiExceptionLogger的相关部分:
public override void Log(ExceptionLoggerContext context)
{
if (context == null || context.ExceptionContext == null) return;
Logger.Error("Unhandled exception from Web API", context.ExceptionContext.Exception);
}
它定期捕获和记录的情况是客户端请求数据集然后在结果(JSON)被发送回来时关闭连接的情况 - 人们在chrome中发出请求,然后点击X所有结果回来之前的按钮:P
为了完整性,我已在下方粘贴了一个堆栈跟踪,只想了解两件事:
我还没有对套接字级别发生的事件序列进行任何深入研究,到目前为止这只是一次日志记录滋扰。
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()
答案 0 :(得分:4)
我在Raspberry Pi上与Owin主机有类似的问题。这有助于https://stackoverflow.com/a/30583109/1786034
答案 1 :(得分:0)
其代码问题
异步读取文件并检查。如果您在进行api调用,并且超时,则肯定会引发异常。
$('.toggle').click(function(){
$('#nav').toggleClass('open');
$('.container').toggleClass('menu-open');
});
$('#nav li').click(function(){
$('#nav').removeClass('open');
$('.container').removeClass('menu-open');
});