fix: Implement correct ratelimit handles for 429's (#2110)
* init * fix errors
This commit is contained in:
@@ -88,7 +88,7 @@ namespace Discord.Net.Queue
|
||||
#if DEBUG_LIMITS
|
||||
Debug.WriteLine($"[{id}] (!) 429");
|
||||
#endif
|
||||
UpdateRateLimit(id, request, info, true);
|
||||
UpdateRateLimit(id, request, info, true, body:response.Stream);
|
||||
}
|
||||
await _queue.RaiseRateLimitTriggered(Id, info, $"{request.Method} {request.Endpoint}").ConfigureAwait(false);
|
||||
continue; //Retry
|
||||
@@ -316,7 +316,7 @@ namespace Discord.Net.Queue
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateRateLimit(int id, IRequest request, RateLimitInfo info, bool is429, bool redirected = false)
|
||||
private void UpdateRateLimit(int id, IRequest request, RateLimitInfo info, bool is429, bool redirected = false, Stream body = null)
|
||||
{
|
||||
if (WindowCount == 0)
|
||||
return;
|
||||
@@ -373,7 +373,17 @@ namespace Discord.Net.Queue
|
||||
Debug.WriteLine($"[{id}] X-RateLimit-Remaining: " + info.Remaining.Value);
|
||||
_semaphore = info.Remaining.Value;
|
||||
}*/
|
||||
if (info.RetryAfter.HasValue)
|
||||
if (is429)
|
||||
{
|
||||
// use the payload reset after value
|
||||
var payload = info.ReadRatelimitPayload(body);
|
||||
|
||||
resetTick = DateTimeOffset.UtcNow.Add(TimeSpan.FromSeconds(payload.RetryAfter));
|
||||
#if DEBUG_LIMITS
|
||||
Debug.WriteLine($"[{id}] Reset-After: {info.ResetAfter.Value} ({info.ResetAfter?.TotalMilliseconds} ms)");
|
||||
#endif
|
||||
}
|
||||
else if (info.RetryAfter.HasValue)
|
||||
{
|
||||
//RetryAfter is more accurate than Reset, where available
|
||||
resetTick = DateTimeOffset.UtcNow.AddSeconds(info.RetryAfter.Value);
|
||||
|
||||
Reference in New Issue
Block a user