The Free Software Media System - Server Backend & API
Properly dispose HttpWebResponse when the request failed to avoid 'too many open files'
Claus Vium2845e7e10173
diff --git a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.csindex 6ea1bd08e6..2232b3eebb 100644--- a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs+++ b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs@@ -66,11 +66,6 @@ namespace Emby.Server.Implementations.HttpClientManager// http://stackoverflow.com/questions/566437/http-post-returns-the-error-417-expectation-failed-cServicePointManager.Expect100Continue = false;--#if NET46-// Trakt requests sometimes fail without this- ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;-#endif}/// <summary>@@ -106,23 +101,6 @@ namespace Emby.Server.Implementations.HttpClientManagerreturn client;}- private static WebRequest CreateWebRequest(string url)- {- try- {- return WebRequest.Create(url);- }- catch (NotSupportedException)- {- //Webrequest creation does fail on MONO randomly when using WebRequest.Create- //the issue occurs in the GetCreator method here: http://www.oschina.net/code/explore/mono-2.8.1/mcs/class/System/System.Net/WebRequest.cs-- var type = Type.GetType("System.Net.HttpRequestCreator, System, Version=4.0.0.0,Culture=neutral, PublicKeyToken=b77a5c561934e089");- var creator = Activator.CreateInstance(type, nonPublic: true) as IWebRequestCreate;- return creator.Create(new Uri(url)) as HttpWebRequest;- }- }-private WebRequest GetRequest(HttpRequestOptions options, string method){string url = options.Url;@@ -135,7 +113,7 @@ namespace Emby.Server.Implementations.HttpClientManagerurl = url.Replace(userInfo + "@", string.Empty);}- var request = CreateWebRequest(url);+ var request = WebRequest.Create(url);if (request is HttpWebRequest httpWebRequest){@@ -627,14 +605,16 @@ namespace Emby.Server.Implementations.HttpClientManagervar exception = new HttpException(webException.Message, webException);- var response = webException.Response as HttpWebResponse;- if (response != null)+ using (var response = webException.Response as HttpWebResponse){- exception.StatusCode = response.StatusCode;-- if ((int)response.StatusCode == 429)+ if (response != null){- client.LastTimeout = DateTime.UtcNow;+ exception.StatusCode = response.StatusCode;++ if ((int)response.StatusCode == 429)+ {+ client.LastTimeout = DateTime.UtcNow;+ }}}