-
Notifications
You must be signed in to change notification settings - Fork 766
fix: websocket keepalive goroutine leak #697
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
base: master
Are you sure you want to change the base?
Conversation
|
Hello @mdawar, Thanks for your contribution, we will check it and get back to you! |
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.
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (1)
v2/common/websocket/client.go:385
- Closing c.done directly on an error may lead to a panic if ReadMessage is called concurrently or if multiple errors occur. Consider guarding the close with a sync.Once or check if the channel is already closed.
if err != nil { close(c.done) }
|
Hello @mdawar , See keepalive log messages like The same thing you will get if you emulate disconnect by server. KeepAlive handler will exit. |
|
@vigodsky yes sure I know that these goroutines will eventually exit on the next tick, but it's usually a best practice to exit immediately, I had a lot of errors from the |
|
@mdawar I agree, but in such case I would recommend to use context. It's safer then closing channel (when you lost control which channel and when was closed) |
|
@vigodsky You're totally right, closing the channel carries the risk of a panic in the WebSocket client. |
The current WebSocket
keepAlivefunction does not exit on connection close or error.This pull request fixes the goroutine leak caused by waiting to receive on the ticker channel and not exiting on connection close.
I made the same change to all instances of the
keepAlivefunction as it's being duplicated in multiple packages (Obviously this needs to be refactored).The
keepAlivemethod in thewebsocketpackage required a newdonechannel that is closed onReadMessageerrors which are considered fatal and will cause a reconnect.