-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
fix(WebSocketShard): wsCloseTimeout in wrong if #8981
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ |
this.closeEmitted = false; | ||
this.debug( | ||
`[WebSocket] Adding a WebSocket close timeout to ensure a correct WS reconnect. | ||
Timeout: ${this.manager.client.options.closeTimeout}ms`, | ||
); | ||
this.setWsCloseTimeout(this.manager.client.options.closeTimeout); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes are very similar to the
file: https://github.com/legendhimself/discord.js/blob/01797d3b0cd316a97853f34a971034c1904b4efb/packages/discord.js/src/client/websocket/WebSocketShard.js#L824
pr: #7626
this.connection.close(closeCode);
Once this ^ is invoked the connection is either CLOSING or CLOSED state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's only CLOSING state, never CLOSED (because it was OPEN before the .close() call), so yes it is similar, but not exactly the same. Especially because there are other reasons why the Websocket could be CLOSED that shouldn't need a wsCloseTimeout because they already closed the Websocket.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CLOSED
check was added for very large scaled bots (Just to cover every case). And after close() is invoked the ws waits for the close frame and then marks the connection CLOSED
. Receiving that close frame differs (might be instant and can happen when the execution is in the current scope) hence that's why I had the check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Websocket doesn’t wait for the close frame though… it’s an async callback. So that‘ll never happen while in this scope, status will always be CLOSING here…
It can be closed, it's superseded by #8989 |
Please describe the changes this PR makes and why it should be merged:
Fixes issues introduced by #8956 because it added the
wsCloseTimeout
even when the Websocket was alreadyClosed
before. This lead to the timeout trying to close the new connection after it successfully reconnected.Also added a clearing of the
wsCloseTimeout
before making a new connection to prevent any other obscure occurences like this.Status and versioning classification: