From 4a6d630076abeeb2fce1f0d6795a3548a8a3499a Mon Sep 17 00:00:00 2001 From: Diego Heras Date: Sun, 16 Jan 2022 13:04:50 +0100 Subject: [PATCH] core: increate httpclient timeout for update download. resolves #12711 (#12836) * Update download timeout => 100s => 300 s --- src/Jackett.Common/Services/UpdateService.cs | 4 ++++ src/Jackett.Common/Utils/Clients/HttpWebClient.cs | 3 +++ src/Jackett.Common/Utils/Clients/HttpWebClient2.cs | 8 ++++++++ src/Jackett.Common/Utils/Clients/WebClient.cs | 3 +++ 4 files changed, 18 insertions(+) diff --git a/src/Jackett.Common/Services/UpdateService.cs b/src/Jackett.Common/Services/UpdateService.cs index 3eb02831d..fa43fec13 100644 --- a/src/Jackett.Common/Services/UpdateService.cs +++ b/src/Jackett.Common/Services/UpdateService.cs @@ -44,6 +44,10 @@ namespace Jackett.Common.Services filePermissionService = fps; variant = new Variants().GetVariant(); + + // Increase the HTTP client timeout just for update download (not other requests) + // The update is heavy and can take longer time for slow connections. Fix #12711 + client.SetTimeout(300); // 5 minutes } public void StartUpdateChecker() => Task.Factory.StartNew(UpdateWorkerThread); diff --git a/src/Jackett.Common/Utils/Clients/HttpWebClient.cs b/src/Jackett.Common/Utils/Clients/HttpWebClient.cs index e86d0939d..1de621859 100644 --- a/src/Jackett.Common/Utils/Clients/HttpWebClient.cs +++ b/src/Jackett.Common/Utils/Clients/HttpWebClient.cs @@ -49,6 +49,8 @@ namespace Jackett.Common.Utils.Clients return sslPolicyErrors == SslPolicyErrors.None; } + public override void SetTimeout(int seconds) => ClientTimeout = seconds; + public override void Init() { base.Init(); @@ -92,6 +94,7 @@ namespace Jackett.Common.Utils.Clients clearanceHandlr.InnerHandler = clientHandlr; using (var client = new HttpClient(clearanceHandlr)) { + client.Timeout = TimeSpan.FromSeconds(ClientTimeout); using (var request = new HttpRequestMessage()) { request.Headers.ExpectContinue = false; diff --git a/src/Jackett.Common/Utils/Clients/HttpWebClient2.cs b/src/Jackett.Common/Utils/Clients/HttpWebClient2.cs index be58336bc..080b1b17b 100644 --- a/src/Jackett.Common/Utils/Clients/HttpWebClient2.cs +++ b/src/Jackett.Common/Utils/Clients/HttpWebClient2.cs @@ -77,6 +77,8 @@ namespace Jackett.Common.Utils.Clients clearanceHandlr.InnerHandler = clientHandlr; client = new HttpClient(clearanceHandlr); + + SetTimeout(ClientTimeout); } // Called everytime the ServerConfig changes @@ -90,6 +92,12 @@ namespace Jackett.Common.Utils.Clients } } + public override void SetTimeout(int seconds) + { + ClientTimeout = seconds; + client.Timeout = TimeSpan.FromSeconds(ClientTimeout); + } + public override void Init() { base.Init(); diff --git a/src/Jackett.Common/Utils/Clients/WebClient.cs b/src/Jackett.Common/Utils/Clients/WebClient.cs index 82fabce55..f8ca24bb9 100644 --- a/src/Jackett.Common/Utils/Clients/WebClient.cs +++ b/src/Jackett.Common/Utils/Clients/WebClient.cs @@ -25,6 +25,7 @@ namespace Jackett.Common.Utils.Clients protected DateTime lastRequest = DateTime.MinValue; protected TimeSpan requestDelayTimeSpan; protected string ClientType; + protected int ClientTimeout = 100; // default timeout is 100 s public bool EmulateBrowser = true; protected static Dictionary> trustedCertificates = new Dictionary>(); @@ -224,6 +225,8 @@ namespace Jackett.Common.Utils.Clients InitProxy(serverConfig); } + public virtual void SetTimeout(int seconds) => throw new NotImplementedException(); + /** * This method does the same as FormUrlEncodedContent but with custom encoding instead of utf-8 * https://stackoverflow.com/a/13832544