core: increate httpclient timeout for update download. resolves #12711 (#12836)

* Update download timeout => 100s => 300 s
This commit is contained in:
Diego Heras
2022-01-16 13:04:50 +01:00
committed by GitHub
parent f11bea6429
commit 4a6d630076
4 changed files with 18 additions and 0 deletions

View File

@@ -44,6 +44,10 @@ namespace Jackett.Common.Services
filePermissionService = fps; filePermissionService = fps;
variant = new Variants().GetVariant(); 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); public void StartUpdateChecker() => Task.Factory.StartNew(UpdateWorkerThread);

View File

@@ -49,6 +49,8 @@ namespace Jackett.Common.Utils.Clients
return sslPolicyErrors == SslPolicyErrors.None; return sslPolicyErrors == SslPolicyErrors.None;
} }
public override void SetTimeout(int seconds) => ClientTimeout = seconds;
public override void Init() public override void Init()
{ {
base.Init(); base.Init();
@@ -92,6 +94,7 @@ namespace Jackett.Common.Utils.Clients
clearanceHandlr.InnerHandler = clientHandlr; clearanceHandlr.InnerHandler = clientHandlr;
using (var client = new HttpClient(clearanceHandlr)) using (var client = new HttpClient(clearanceHandlr))
{ {
client.Timeout = TimeSpan.FromSeconds(ClientTimeout);
using (var request = new HttpRequestMessage()) using (var request = new HttpRequestMessage())
{ {
request.Headers.ExpectContinue = false; request.Headers.ExpectContinue = false;

View File

@@ -77,6 +77,8 @@ namespace Jackett.Common.Utils.Clients
clearanceHandlr.InnerHandler = clientHandlr; clearanceHandlr.InnerHandler = clientHandlr;
client = new HttpClient(clearanceHandlr); client = new HttpClient(clearanceHandlr);
SetTimeout(ClientTimeout);
} }
// Called everytime the ServerConfig changes // 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() public override void Init()
{ {
base.Init(); base.Init();

View File

@@ -25,6 +25,7 @@ namespace Jackett.Common.Utils.Clients
protected DateTime lastRequest = DateTime.MinValue; protected DateTime lastRequest = DateTime.MinValue;
protected TimeSpan requestDelayTimeSpan; protected TimeSpan requestDelayTimeSpan;
protected string ClientType; protected string ClientType;
protected int ClientTimeout = 100; // default timeout is 100 s
public bool EmulateBrowser = true; public bool EmulateBrowser = true;
protected static Dictionary<string, ICollection<string>> trustedCertificates = new Dictionary<string, ICollection<string>>(); protected static Dictionary<string, ICollection<string>> trustedCertificates = new Dictionary<string, ICollection<string>>();
@@ -224,6 +225,8 @@ namespace Jackett.Common.Utils.Clients
InitProxy(serverConfig); 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 * This method does the same as FormUrlEncodedContent but with custom encoding instead of utf-8
* https://stackoverflow.com/a/13832544 * https://stackoverflow.com/a/13832544