Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
Gateway disconnect update (reconnect only)
Browse files Browse the repository at this point in the history
  • Loading branch information
Defxult committed Oct 18, 2023
1 parent 4ab0a44 commit 5beae0d
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions Sources/Discord/Gateway.swift
Original file line number Diff line number Diff line change
Expand Up @@ -358,22 +358,14 @@ class Gateway {
}
}

if ws.closeCode == nil {
// A new session must be started here. If the connection is closed with a nil close code,
// vapor disconnected (for whatever reason). If that occurs, simply reconnecting somehow makes
// the stability of the connection even worse by having it disconnect randomly more frequently,
// sometimes significantly more frequent. Creating a brand new connection "refreshes" connection
// stability.
Log.message("connection closed with nil close code - starting new session...")
newConnection(type: .session)
} else {
// If the end user did not terminate the connection, we should always reconnect.
// Also, if this is reached, that means it did not `return`. If it returned, a new
// session was required, not a reconnect. Additionally, .isConnected will never be
// set to `false` unless done so by the end user via Bot.disconnect() or Bot.close()
if bot.isConnected {
newConnection(type: .reconnect)
}
// If the end user did not terminate the connection, we should always reconnect.
// Also, if this is reached, that means it did not `return`. If it returned within
// the `switch` statement, a new session was required, not a reconnect. Additionally,
// .isConnected will never be set to `false` unless done so by the end user via
// Bot.disconnect() or Bot.close()
if bot.isConnected {
if ws.closeCode == nil { Log.message("gateway closed with nil close code - reconnecting...") }
newConnection(type: .reconnect)
}
}

Expand Down

0 comments on commit 5beae0d

Please sign in to comment.