Update subscription timeout is set to 30 seconds

pull/2295/head
2dust 2022-04-30 08:32:26 +08:00
parent 2a11fe11e8
commit bcda8bd602
2 changed files with 7 additions and 6 deletions

View File

@ -56,7 +56,7 @@ namespace v2rayN.Base
} }
return null; return null;
} }
public async Task<string> GetAsync(HttpClient client, string url) public async Task<string> GetAsync(HttpClient client, string url, CancellationToken token)
{ {
if (string.IsNullOrEmpty(url)) if (string.IsNullOrEmpty(url))
{ {
@ -64,10 +64,7 @@ namespace v2rayN.Base
} }
try try
{ {
var cts = new CancellationTokenSource(); HttpResponseMessage response = await client.GetAsync(url, token);
cts.CancelAfter(5000);
HttpResponseMessage response = await client.GetAsync(url, cts.Token);
return await response.Content.ReadAsStringAsync(); return await response.Content.ReadAsStringAsync();
} }
catch (Exception ex) catch (Exception ex)

View File

@ -156,7 +156,11 @@ namespace v2rayN.Handler
{ {
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Utils.Base64Encode(uri.UserInfo)); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Utils.Base64Encode(uri.UserInfo));
} }
var result = await HttpClientHelper.GetInstance().GetAsync(client, url);
var cts = new CancellationTokenSource();
cts.CancelAfter(1000 * 30);
var result = await HttpClientHelper.GetInstance().GetAsync(client, url, cts.Token);
return result; return result;
} }
catch (Exception ex) catch (Exception ex)