From 8de69603351f8e6515d09f42b75693200f319bcb Mon Sep 17 00:00:00 2001 From: Ske Date: Thu, 12 Aug 2021 08:59:48 +0200 Subject: [PATCH] Add HTTP timeout/retry to Twilight rate limiter --- .../Limit/TwilightGatewayRatelimiter.cs | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Myriad/Gateway/Limit/TwilightGatewayRatelimiter.cs b/Myriad/Gateway/Limit/TwilightGatewayRatelimiter.cs index 036c4ac5..51841717 100644 --- a/Myriad/Gateway/Limit/TwilightGatewayRatelimiter.cs +++ b/Myriad/Gateway/Limit/TwilightGatewayRatelimiter.cs @@ -1,4 +1,5 @@ -using System.Net.Http; +using System; +using System.Net.Http; using System.Threading.Tasks; using Serilog; @@ -9,7 +10,10 @@ namespace Myriad.Gateway.Limit { private readonly string _url; private readonly ILogger _logger; - private readonly HttpClient _httpClient = new(); + private readonly HttpClient _httpClient = new() + { + Timeout = TimeSpan.FromSeconds(60) + }; public TwilightGatewayRatelimiter(ILogger logger, string url) { @@ -19,9 +23,19 @@ namespace Myriad.Gateway.Limit public async Task Identify(int shard) { - // Literally just request and wait :p - _logger.Information("Shard {ShardId}: Requesting identify at gateway queue {GatewayQueueUrl}", shard, _url); - await _httpClient.GetAsync(_url); + while (true) + { + try + { + _logger.Information("Shard {ShardId}: Requesting identify at gateway queue {GatewayQueueUrl}", + shard, _url); + await _httpClient.GetAsync(_url); + return; + } + catch (TimeoutException) + { + } + } } } } \ No newline at end of file