Skip to content

Commit ffb511e

Browse files
committed
Do not schedule bucket expiry again after initial response
In case multiple responses come in, it does not make sense to expire the bucket again and again. We should only do this once for the initial bucket, because otherwise on subsequent requests in the next ratelimit window we might expire it, which is wrong.
1 parent e197d9f commit ffb511e

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

lib/nostrum/api/ratelimiter.ex

+1-4
Original file line numberDiff line numberDiff line change
@@ -771,8 +771,6 @@ defmodule Nostrum.Api.Ratelimiter do
771771
%{outstanding: outstanding} = data
772772
)
773773
when remaining >= 0 do
774-
expire_bucket = {{:timeout, bucket}, reset_after, :expired}
775-
776774
case Map.fetch(outstanding, bucket) do
777775
# This is the first response we got for the absolute initial call.
778776
# Update the remaining value to the reported value.
@@ -781,7 +779,7 @@ defmodule Nostrum.Api.Ratelimiter do
781779

782780
{:keep_state, %{data | outstanding: updated_outstanding},
783781
[
784-
expire_bucket,
782+
{{:timeout, bucket}, reset_after, :expired},
785783
{:next_event, :internal, {:next, remaining, bucket}}
786784
]}
787785

@@ -800,7 +798,6 @@ defmodule Nostrum.Api.Ratelimiter do
800798
{:ok, {stored_remaining, _queue}} ->
801799
{:keep_state_and_data,
802800
[
803-
expire_bucket,
804801
{:next_event, :internal, {:next, stored_remaining, bucket}}
805802
]}
806803

0 commit comments

Comments
 (0)