From 4d8c3f5c65b24b3ace15ac6c103b75956d24d6c8 Mon Sep 17 00:00:00 2001 From: Paulo Date: Sat, 23 May 2020 11:32:37 -0300 Subject: [PATCH] Don't disable when there's no resetTick Sometimes Discord won't send any ratelimit headers, disabling the semaphore for endpoints that should have them. --- src/Discord.Net.Rest/Net/Queue/RequestQueueBucket.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Discord.Net.Rest/Net/Queue/RequestQueueBucket.cs b/src/Discord.Net.Rest/Net/Queue/RequestQueueBucket.cs index 771923cd4..65b1e08a7 100644 --- a/src/Discord.Net.Rest/Net/Queue/RequestQueueBucket.cs +++ b/src/Discord.Net.Rest/Net/Queue/RequestQueueBucket.cs @@ -277,16 +277,16 @@ namespace Discord.Net.Queue #endif } - if (resetTick == null) + /*if (resetTick == null) { WindowCount = 0; //No rate limit info, disable limits on this bucket (should only ever happen with a user token) #if DEBUG_LIMITS Debug.WriteLine($"[{id}] Disabled Semaphore"); #endif return; - } + }*/ - if (!hasQueuedReset || resetTick > _resetTick) + if (resetTick != null && (!hasQueuedReset || resetTick > _resetTick)) { _resetTick = resetTick; LastAttemptAt = resetTick.Value; //Make sure we dont destroy this until after its been reset @@ -299,6 +299,8 @@ namespace Discord.Net.Queue var _ = QueueReset(id, (int)Math.Ceiling((_resetTick.Value - DateTimeOffset.UtcNow).TotalMilliseconds)); } } + else if (!hasQueuedReset && _semaphore == 0) + _semaphore = WindowCount; //Prevent getting locked at 0/1 if Discord doesn't send the ratelimit headers } } private async Task QueueReset(int id, int millis)