Tags: albeebe/websocket
Tags
Enhance WebSocket error handling and message queueing logic Introduced panic recovery in readMessages and SendMessage to prevent application crashes due to unexpected panics. Improved handling of closed channels in writeMessages to avoid runtime errors. Added checks for context cancellation (Context.Done) in SendMessage and writeMessages for better connection management. Used a mutex to ensure thread-safe access to the WebSocket connection when sending messages in writeMessages. Enhanced error handling when the outgoing message buffer is full, ensuring graceful connection closure. Updated SendMessage to clarify behavior during context cancellation and buffer overflow scenarios.
Send disconnection notification regardless of error presence This change ensures the Disconnected channel is notified when the connection is closed, regardless of whether an error occurred. Previously, the notification was only sent if an error was present.
Add unit tests for WebSocket client and initialize Go module - Added unit tests for the WebSocket client to verify connection establishment, message sending, message receiving, and disconnection handling. - Created Go module file (go.mod) to manage dependencies, including Gorilla WebSocket and Testify libraries. - Ensured robust testing of WebSocket communication flow using httptest servers.