首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Grapevine.Interfaces.Server.HttpResponse.SendResponse中未处理的异常

Grapevine.Interfaces.Server.HttpResponse.SendResponse中未处理的异常
EN

Stack Overflow用户
提问于 2017-12-12 18:52:04
回答 1查看 328关注 0票数 1

我有一个服务器,它监听多个客户端发送信息的HTTP帖子。我使用Grapevine作为http服务器,因为方法非常简单,不需要ASP的复杂性。

有时我会被随机

误差

代码语言:javascript
复制
2017-12-12 15:39:25.5642|ERROR|Omnibox_Server.Modelo.HttpServer.Controllers.OpenALPRController|System.Net.HttpListenerException (0x80004005): The I/O operation has been aborted because of either a thread exit or an application request
   at System.Net.HttpRequestStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.IO.StreamReader.ReadBuffer()
   at System.IO.StreamReader.ReadToEnd()
   at Grapevine.Interfaces.Server.HttpRequest.get_Payload()
   at Omnibox_Server.Modelo.HttpServer.Controllers.OpenALPRController.PostPatente(IHttpContext context)

这是

类/方法:

代码语言:javascript
复制
namespace Omnibox_Server.Modelo.HttpServer.Controllers
{
    [RestResource(BasePath = "/openalpr")]
    public class OpenALPRController
    {
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
        [RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "/patente")]
        public IHttpContext PostPatente(IHttpContext context)
        {
            try
            {
                context.Response.StatusCode = HttpStatusCode.Ok;
                context.Response.ContentType = ContentType.JSON;
                context.Response.ContentEncoding = Encoding.UTF8;
                var fotoOpenAlpr = JsonConvert.DeserializeObject<FotoOpenALPR>(context.Request.Payload); //<--- exception occurs here? shouldn't try/catch work?
                var ip = context.Request.RemoteEndPoint;
                if (fotoOpenAlpr.agent_uid != null)
                    Task.Run(async () =>
                    {
                        if (fotoOpenAlpr.is_parked) return;
                        await fotoOpenAlpr.ObtenerFoto(ip.Address);
                        try
                        {
                            var foto = new Foto(fotoOpenAlpr);
                            if (foto.IdOmnibox == 0) Logger.Info("Omnibox sin ID con IP " + ip.Address);
                            await foto.Procesar();
                        }
                        catch (Exception e)
                        {
                        }
                    });
                context.Response.SendResponse(HttpStatusCode.Ok); //or maybe exception triggers here?
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
            return context;
        }
    }
}

中生成一个事件。

windows日志:

代码语言:javascript
复制
Application: Omnibox Server.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Net.HttpListenerException
   at System.Net.HttpResponseStream.Write(Byte[], Int32, Int32)
   at Grapevine.Interfaces.Server.HttpResponse.SendResponse(Byte[])
   at Grapevine.Server.HttpResponseExtensions.SendResponse(Grapevine.Interfaces.Server.IHttpResponse, System.String)
   at Grapevine.Server.Router.Route(System.Object)
   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

事件查看器中的异常日志和windows日志具有相同的时间戳。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-29 17:21:17

从执行部分:

我通过将行context.Response.SendResponse(HttpStatusCode.Ok);移至try/catch下面来解决这个问题。我认为所发生的情况是,有时TCP管道中断和有效负载损坏/不完整,因此在尝试获取它时会抛出一个异常,而且由于我没有SendResponse(OK),在try/catch之外抛出了另一个异常,从而破坏了我的服务器。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47779634

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档