Fix websocket panic issue#3455
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Owner
Author
|
bugbot run |
Owner
Author
|
bugbot run |
a97ab3e to
f78a80c
Compare
Owner
Author
|
bugbot run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3431
A WebSocket panic due to concurrent writes was addressed by implementing per-connection write synchronization.
Key changes include:
connectionInfostruct was introduced inbackend/websocket/websocket.go, embedding a*websocket.Connand async.Mutexfor write protection.WebsocketServer.connectionsmap was updated to storemap[string]*connectionInfoinstead ofmap[string]*websocket.Conn.SendMessagefunction inbackend/websocket/messages.gowas refactored to accept a*connectionInfoand acquire itswriteMuxbefore callingconn.WriteJSON(), ensuring thread safety for writes to that specific connection.SendMessageand connection management functions, includingAddConnection,RemoveConnection,handleMessages,BroadcastModuleUpdate, andSendErrorinbackend/websocket/handlers.goandbackend/websocket/messages.go, were updated to utilize the newconnectionInfostructure.This approach prevents concurrent writes to the same WebSocket connection, resolving the panic, while allowing concurrent writes to different connections for optimal performance.