Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to fix invalid sessions received when reconnecting to the Gateway #592

Merged
merged 6 commits into from
Nov 26, 2023

Conversation

abitofevrything
Copy link
Member

Description

A few users have been experiencing INVALID_SESSION events after their client reconnects to the Gateway, for no apparent reason. Testing reveals this is pretty easy to reproduce simply by cutting the client's internet connection and reconnecting it once the reconnect loop starts (it's also easier to reproduce with lower ping intervals).

A theory I have as to why this happens is that when we disconnect with the intent to reconnect later (or when a ping fails, in which case we also try to reconnect), the websocket is closed with a 1000 (when we close it) or a 1001 (when a ping fails). Discord considers these "normal" close codes, and terminates the session. When we then try to resume, the session is already closed.

At least, that's my theory. For now I've removed the ping interval (since heartbeats effectively do the same thing) and changed all close codes to be non-"normal" (other than when disposing, since that is a case where we do want Discord to end the session).

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • Ran dart analyze or make analyze and fixed all issues
  • Ran dart format --set-exit-if-changed -l 160 ./lib or make format and fixed all issues
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

@abitofevrything abitofevrything added the bug Something isn't working label Nov 26, 2023
@abitofevrything abitofevrything added this to the 6.0.3 milestone Nov 26, 2023
@abitofevrything abitofevrything self-assigned this Nov 26, 2023
@abitofevrything abitofevrything merged commit 46f128c into dev Nov 26, 2023
@abitofevrything abitofevrything deleted the bug/shard-invalid-session-reconnect branch November 26, 2023 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants