-
Notifications
You must be signed in to change notification settings - Fork 831
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
feat(wsapi): Gracefully close the websocket connection #1347
base: master
Are you sure you want to change the base?
Conversation
@@ -951,3 +938,36 @@ func (s *Session) CloseWithCode(closeCode int) (err error) { | |||
|
|||
return | |||
} | |||
|
|||
func (s *Session) doCloseHandshake(closeCode int) error { |
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.
After a bit of thinking. It might be a good idea to also move this function away from Session
into util.go
, with websocket
prefixed name (e.g. doWebsocketCloseHandshake
). Since we can reuse it in our voice websocket handling code.
} | ||
|
||
// Wait for Discord to actually close the connection. | ||
// To prevent ping, pong and close handlers from setting the read deadline, |
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.
setting read deadline
I'm not quite sure what do you refer to. The handlers in websocket
by default don't extend the read deadline. And we don't override them (well, close is overriden, but is noop)
This PR removes a
time.Sleep(1 * time.Second)
fromSession.Close()
.Instead, I implemented the websocket close handshake described in this comment: gorilla/websocket#448 (comment)
The reason I would like to see this change is that the
time.Sleep
was causing my unit tests to run slowly.I tested this change by running this program a few times: