discordgo icon indicating copy to clipboard operation
discordgo copied to clipboard

Resume improvements

Open FedorLap2006 opened this issue 2 years ago • 2 comments

This PR aims to improve interface for resuming sessions between crashes and program restarts. Additionally this PR implements newly added resume_gateway_url (however this might be separated into a different PR soon)

FedorLap2006 avatar Feb 27 '22 15:02 FedorLap2006

If resuming the gateway connection fails, the gateway responds with an opcode 9 ("Invalid Session") message. Discordgo catches this and automatically reidentifies. This is the expected result of receiving an opcode 9 message when automatically resuming, but not ideal when manually resuming.

IMO, the best way around this would probably be to add a dedicated Session::Resume() method that will attempt to resume and return an error if Discord responds with opcode 9.

The main use case for having such a method is to allow for zero-downtime restarts for very large bots. Due to the way resuming works, you must send a resume packet within a few seconds of disconnecting, or it will fail with opcode 9. If you are trying to resume a large number of shards, you must resume all of them at once, instead of doing it in batches like you do with identifies. If >16 shards fail to resume, they will get ratelimited when they automatically identify.

Relevant lines: https://github.com/bwmarrin/discordgo/blob/9e96d380d4e1ddd1b6049064fabfb6c37a4b7b59/wsapi.go#L171-L178 https://github.com/bwmarrin/discordgo/blob/9e96d380d4e1ddd1b6049064fabfb6c37a4b7b59/wsapi.go#L542-L553

Benricheson101 avatar Feb 28 '22 17:02 Benricheson101

Any updates on this?

fr3fou avatar May 05 '23 22:05 fr3fou