From d071f19654874d8a1cabbf18d7c3de73f04113d8 Mon Sep 17 00:00:00 2001 From: kaso17 Date: Wed, 25 Jan 2017 18:40:40 +0100 Subject: [PATCH] Owin: set HttpListener.IgnoreWriteExceptions = true --- src/Jackett/Startup.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Jackett/Startup.cs b/src/Jackett/Startup.cs index 239a44956..cbc0a1ccf 100644 --- a/src/Jackett/Startup.cs +++ b/src/Jackett/Startup.cs @@ -17,6 +17,7 @@ using System.Web.Http.Tracing; using Jackett.Utils; using Microsoft.AspNet.Identity; using System.Web.Http.ExceptionHandling; +using System.Net; [assembly: OwinStartup(typeof(Startup))] namespace Jackett @@ -82,6 +83,23 @@ namespace Jackett // Configure Web API for self-host. var config = new HttpConfiguration(); + // try to fix SocketException crashes + // based on http://stackoverflow.com/questions/23368885/signalr-owin-self-host-on-linux-mono-socketexception-when-clients-lose-connectio/30583109#30583109 + try + { + object httpListener; + if (appBuilder.Properties.TryGetValue(typeof(HttpListener).FullName, out httpListener) && httpListener is HttpListener) + { + // HttpListener should not return exceptions that occur when sending the response to the client + ((HttpListener)httpListener).IgnoreWriteExceptions = true; + Engine.Logger.Info("set HttpListener.IgnoreWriteExceptions = true"); + } + } + catch (Exception e) + { + Engine.Logger.Error(e, "Error while setting HttpListener.IgnoreWriteExceptions = true"); + } + appBuilder.Use(); // register exception handler