Skip to content

Commit 0b66b26

Browse files
committed
Brutally close connection on gun_down
Similar reason as for the ratelimiter
1 parent 7ebffa9 commit 0b66b26

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/nostrum/shard/event.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ defmodule Nostrum.Shard.Event do
2121
if payload.t == :READY do
2222
Logger.info("READY")
2323

24-
{%{state | session: payload.d.session_id, resume_gateway: payload.d.resume_gateway_url},
25-
[]}
24+
{%{state | session: payload.d.session_id, resume_gateway: payload.d.resume_gateway_url}, []}
2625
else
2726
{state, []}
2827
end

lib/nostrum/shard/session.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,11 @@ defmodule Nostrum.Shard.Session do
266266
%{conn: conn} = data
267267
) do
268268
Logger.info("Lost complete shard connection. Attempting reconnect.")
269-
:gun.flush(conn)
269+
# Brutally close to make sure we don't mess up the state machine
270+
# due to gun reconnecting automatically. For the WebSocket disconnect
271+
# case, this is fine.
272+
:ok = :gun.close(conn)
273+
:ok = :gun.flush(conn)
270274
connect = {:next_event, :internal, :connect}
271275
{:next_state, :disconnected, %{data | conn: nil, stream: nil}, connect}
272276
end

0 commit comments

Comments
 (0)