Skip to content

Commit acbe743

Browse files
committed
Keep outstanding requests on connection crash
The ratelimiter would previously not take `outstanding` requests with it when it would transition to `:disconnected` state, resulting in pending requests being silently dropped. Fixes #669.
1 parent 5e8b234 commit acbe743

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/nostrum/api/ratelimiter.ex

+4-2
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,8 @@ defmodule Nostrum.Api.Ratelimiter do
904904

905905
def connected(:info, {:gun_down, conn, _, reason, killed_streams}, %{
906906
running: running,
907-
wrapped_token: wrapped_token
907+
wrapped_token: wrapped_token,
908+
outstanding: outstanding
908909
}) do
909910
# Even with `retry: 0`, gun seems to try and reconnect, potentially because
910911
# of WebSocket. Force the connection to die.
@@ -926,7 +927,8 @@ defmodule Nostrum.Api.Ratelimiter do
926927
{:reply, client, {:error, {:connection_died, reason}}}
927928
end)
928929

929-
{:next_state, :disconnected, empty_state(wrapped_token.()), replies}
930+
new_data = %{empty_state(wrapped_token.()) | outstanding: outstanding}
931+
{:next_state, :disconnected, new_data, replies}
930932
end
931933

932934
def global_limit(:state_timeout, next, data) do

0 commit comments

Comments
 (0)