8000 fix: multiple gateway logic bugfixes by davfsa · Pull Request #468 · disgoorg/disgo · GitHub
[go: up one dir, main page]

Skip to content

fix: multiple gateway logic bugfixes - #468

Merged
topi314 merged 17 commits into
disgoorg:masterfrom
davfsa:fix/proper-initial-resume-logic
Aug 25, 2025
Merged

topi314 merged 17 commits into
disgoorg:masterfrom
davfsa:fix/proper-initial-resume-logic

Conversation

@davfsa
@davfsa davfsa commented Aug 22, 2025 •
Copy link
Copy Markdown
Contributor
  • Properly scope sync.Once to avoid deadlocks
  • Add defer ready(nil) to listen to ensure it never leaves without setting the channel (avoid deadlocks)
  • Pass an error to ready on invalid session and reconnect (if shard is not ready) to avoid open from thinking the shard has successfully started when it hasn't
    • This also helps the sharder not believe the shards are up
  • Replace reconnectTry with doReconnect, which is the same logic but it removes the recursiveness
  • Fix potential null pointer dereference in reconnect,
  • Set ready channel as an unbuffered channel
  • Improve logging for invalid sessions/reconnects
  • Properly handle RECONNECT as the first opcode
  • Switch to an exponential backoff of up to 10s to avoid very long disconnect times
  • Disconnect shard if no ACK is received between heartbeats (shard went zombie)
  • Initial heartbeat jitter

@davfsa
davfsa marked this pull request as draft August 22, 2025 15:10
@davfsa
davfsa marked this pull request as ready for review August 22, 2025 17:56
@GoLittie
Copy link
Copy Markdown

the goat

Comment thread gateway/gateway.go Resolved
Comment thread gateway/gateway.go Resolved
Comment thread gateway/gateway.go Resolved
Comment thread gateway/gateway.go Resolved
Comment thread gateway/gateway.go Resolved
Comment thread gateway/gateway.go Resolved
Comment thread gateway/gateway.go Resolved
Comment thread gateway/gateway.go Resolved
Comment thread gateway/gateway.go Outdated
g.config.SessionID = &readyEvent.SessionID
g.config.ResumeURL = &readyEvent.ResumeGatewayURL
g.config.Logger.Debug("ready message received")
g.config.Logger.Info("succesfully started", slog.String("sessionID", *g.config.SessionID))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too verbose to be info level

Suggested change
g.config.Logger.Info("succesfully started", slog.String("sessionID", *g.config.SessionID))
g.config.Logger.Debug("succesfully started", slog.String("session_id", *g.config.SessionID))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I moved them to Info is because they give insights to the shard without having to enable debug, which just spams the console for very large bots.

At the moment, any level of information is just behind the debug level and would be nice to move them out

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can handle the event in your code and log there if needed, or you could also log to a file and grep the output.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it would be worth considering adding a level below debug for payloads?
then running debug wouldn't be as spammy

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, payloads could be logged at slog.LevelDebug-1

Comment thread gateway/gateway.go Resolved
@davfsa
davfsa requested a review from apricotbucket28 August 23, 2025 07:52
@apricotbucket28 apricotbucket28 left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

@topi314 topi314 left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks pretty good!
just some minor stuff

Comment thread gateway/gateway.go Resolved
Comment thread gateway/gateway.go Resolved
Comment thread gateway/gateway.go Resolved
Comment thread gateway/gateway.go Resolved
Comment thread gateway/gateway.go Resolved
@davfsa
davfsa requested a review from topi314 August 23, 2025 23:06
@topi314 topi314 left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks alright now!

@topi314
topi314 merged commit 1c13eea into disgoorg:master Aug 25, 2025
@topi314
topi314 commented Aug 25, 2025
Copy link
Copy Markdown
Member

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants

0