From 9de86fc2175d07fa29a1386dc7eeca52ec47b1ba Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Wed, 13 Nov 2024 17:16:50 +0100 Subject: [PATCH] feat: add read timeout for server messages --- internal/websocket/receive.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/websocket/receive.go b/internal/websocket/receive.go index e4638a6..7912de3 100644 --- a/internal/websocket/receive.go +++ b/internal/websocket/receive.go @@ -19,6 +19,7 @@ func (c *Client) ProcessServerMessages(channel chan<- GoTomato.ServerMessage) { defer close(Done) for { + c.Conn.SetReadDeadline(time.Now().Add(10 * time.Second)) _, message, err := c.Conn.ReadMessage() if err != nil { // On normal closure exit gracefully @@ -26,6 +27,7 @@ func (c *Client) ProcessServerMessages(channel chan<- GoTomato.ServerMessage) { return } + c.LastErr = err // Try to reconnect on unexpected disconnect for { channel <- prevMessage // send previous ServerMessage to update view