Browse Source

Fixes RetryMode.RetryRatelimit being ignored (#1036)

tags/2.0
HelpfulStranger999 Christopher F 7 years ago
parent
commit
c618cb3ccd
1 changed files with 10 additions and 5 deletions
  1. +10
    -5
      src/Discord.Net.Rest/Net/Queue/RequestQueueBucket.cs

+ 10
- 5
src/Discord.Net.Rest/Net/Queue/RequestQueueBucket.cs View File

@@ -163,7 +163,7 @@ namespace Discord.Net.Queue
if (!isRateLimited) if (!isRateLimited)
throw new TimeoutException(); throw new TimeoutException();
else else
throw new RateLimitedException(request);
ThrowRetryLimit(request);
} }


lock (_lock) lock (_lock)
@@ -181,13 +181,12 @@ namespace Discord.Net.Queue
await _queue.RaiseRateLimitTriggered(Id, null).ConfigureAwait(false); await _queue.RaiseRateLimitTriggered(Id, null).ConfigureAwait(false);
} }


if ((request.Options.RetryMode & RetryMode.RetryRatelimit) == 0)
throw new RateLimitedException(request);
ThrowRetryLimit(request);


if (resetAt.HasValue) if (resetAt.HasValue)
{ {
if (resetAt > timeoutAt) if (resetAt > timeoutAt)
throw new RateLimitedException(request);
ThrowRetryLimit(request);
int millis = (int)Math.Ceiling((resetAt.Value - DateTimeOffset.UtcNow).TotalMilliseconds); int millis = (int)Math.Ceiling((resetAt.Value - DateTimeOffset.UtcNow).TotalMilliseconds);
#if DEBUG_LIMITS #if DEBUG_LIMITS
Debug.WriteLine($"[{id}] Sleeping {millis} ms (Pre-emptive)"); Debug.WriteLine($"[{id}] Sleeping {millis} ms (Pre-emptive)");
@@ -198,7 +197,7 @@ namespace Discord.Net.Queue
else else
{ {
if ((timeoutAt.Value - DateTimeOffset.UtcNow).TotalMilliseconds < 500.0) if ((timeoutAt.Value - DateTimeOffset.UtcNow).TotalMilliseconds < 500.0)
throw new RateLimitedException(request);
ThrowRetryLimit(request);
#if DEBUG_LIMITS #if DEBUG_LIMITS
Debug.WriteLine($"[{id}] Sleeping 500* ms (Pre-emptive)"); Debug.WriteLine($"[{id}] Sleeping 500* ms (Pre-emptive)");
#endif #endif
@@ -309,5 +308,11 @@ namespace Discord.Net.Queue
} }
} }
} }

private void ThrowRetryLimit(RestRequest request)
{
if ((request.Options.RetryMode & RetryMode.RetryRatelimit) == 0)
throw new RateLimitedException(request);
}
} }
} }

Loading…
Cancel
Save