From 8f05e0404b6c4556688211d663c7c0880a75cb60 Mon Sep 17 00:00:00 2001 From: The Major Date: Sun, 23 Jun 2024 19:24:48 +0000 Subject: [PATCH] handle gun_down in shard for non-matching gun conns --- lib/nostrum/shard/session.ex | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/nostrum/shard/session.ex b/lib/nostrum/shard/session.ex index d882ca1c3..52d14f664 100644 --- a/lib/nostrum/shard/session.ex +++ b/lib/nostrum/shard/session.ex @@ -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})