Skip to content

Commit

Permalink
Brutally close connection on gun_down
Browse files Browse the repository at this point in the history
Similar reason as for the ratelimiter
  • Loading branch information
jchristgit committed Jun 2, 2023
1 parent 7ebffa9 commit 0b66b26
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lib/nostrum/shard/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ defmodule Nostrum.Shard.Event do
if payload.t == :READY do
Logger.info("READY")

{%{state | session: payload.d.session_id, resume_gateway: payload.d.resume_gateway_url},
[]}
{%{state | session: payload.d.session_id, resume_gateway: payload.d.resume_gateway_url}, []}
else
{state, []}
end
Expand Down
6 changes: 5 additions & 1 deletion lib/nostrum/shard/session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,11 @@ defmodule Nostrum.Shard.Session do
%{conn: conn} = data
) do
Logger.info("Lost complete shard connection. Attempting reconnect.")
:gun.flush(conn)
# Brutally close to make sure we don't mess up the state machine
# due to gun reconnecting automatically. For the WebSocket disconnect
# case, this is fine.
:ok = :gun.close(conn)
:ok = :gun.flush(conn)
connect = {:next_event, :internal, :connect}
{:next_state, :disconnected, %{data | conn: nil, stream: nil}, connect}
end
Expand Down

0 comments on commit 0b66b26

Please sign in to comment.