Skip to content

Commit

Permalink
Merge pull request #611 from Th3-M4jor/handle-gun-down-when-different…
Browse files Browse the repository at this point in the history
…-gun-conn-pid

Handle case of non matching gun conn pids when receiving a gun_down message
  • Loading branch information
jb3 committed Jun 23, 2024
2 parents 0142400 + 8f05e04 commit e56ac19
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/nostrum/shard/session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,18 @@ defmodule Nostrum.Shard.Session do
{:keep_state_and_data, {:next_event, :internal, :reconnect}}
end

def connected(
:info,
{:gun_down, old_conn, _proto, _reason, _killed_streams},
%{conn: new_conn}
# technically the guard is not needed because of the above clause,
# but it makes the intent a bit clearer
)
when old_conn != new_conn do
Logger.debug("Received gun_down message for a previous shard connection. Ignoring message.")
:keep_state_and_data
end

def connected(:cast, {request, payload}, %{conn: conn, stream: stream})
when request in [:status_update, :update_voice_state, :request_guild_members] do
:ok = :gun.ws_send(conn, stream, {:binary, payload})
Expand Down

0 comments on commit e56ac19

Please sign in to comment.