8000 fix(gateway): fail the open instead of waiting forever when a handshake message fails to decode by dearlyzin · Pull Request #653 · disgoorg/disgo · GitHub
[go: up one dir, main page]

Skip to content

fix(gateway): fail the open instead of waiting forever when a handshake message fails to decode - #653

Closed
dearlyzin wants to merge 2 commits into
disgoorg:masterfrom
dearlyzin:fix/gateway-undecodable-ready
Closed

dearlyzin wants to merge 2 commits into
disgoorg:masterfrom
dearlyzin:fix/gateway-undecodable-ready

Conversation

@dearlyzin
Copy link
Copy Markdown

Description

Fixes #651.

When a gateway message fails to decode, parseMessage logs the error and returns a nil message, and listen just moves on to the next message. That is fine for regular events, but if READY is the one that fails, the shard ends up half-connected:

  • Open blocks until its context ends, since the status only becomes Ready for a decoded EventReady, while holding the identify bucket (blocking the other shards in that bucket too)
  • READY never runs, so guilds the bot is already in fire GuildJoin on every GUILD_CREATE (welcome messages/logs fire for every guild, again on every reconnect)
  • the client is only half initialized: events.Ready never fires, Client.ID() returns 0, Gateway.Send fails with ErrShardNotReady

This PR makes listen treat a nil message as fatal while the gateway is not ready yet: it calls ready with an error and returns, so the pending Open fails immediately and the normal error path (close + reconnect with a fresh session) takes over, instead of waiting forever for a READY that will never decode.

Once ready, nil messages keep being skipped as before, so regular event decode errors don't reconnect the shard.

Tests

Added gateway/gateway_nil_message_test.go:

  • a nil message while waiting for READY fails listen with an error instead of looping (the scenario from the issue)
  • a nil message before HELLO aborts the loop as well
  • (existing behavior after Ready is covered by the status check: nil messages keep being skipped)

go build ./..., go vet ./gateway and go test ./gateway -race all pass.

@topi314
topi314 commented Nov 10, 2026
Copy link
Copy Markdown
Member

beep boop, agent be gone

@dearlyzin
dearlyzin deleted the fix/gateway-undecodable-ready branch November 11, 2026 10:42
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.

Undecodable READY leaves the shard stuck: Open blocks and existing guilds fire GuildJoin

2 participants

0