From 3fb3b1b7949b37ec9230c558d3d85069cf468c9e Mon Sep 17 00:00:00 2001 From: in-void Date: Tue, 7 Mar 2023 23:50:04 +0100 Subject: [PATCH] websocket api: fix websocket connection timeout handling --- internal/websocket/common/handler.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/websocket/common/handler.go b/internal/websocket/common/handler.go index a2290af..dcf5d20 100644 --- a/internal/websocket/common/handler.go +++ b/internal/websocket/common/handler.go @@ -76,15 +76,15 @@ func (h *ConnectionHandler) serveWs(hub *Hub, w http.ResponseWriter, r *http.Req go client.readPump() go func() { - disconnectAfter := time.Duration(3) * time.Minute + disconnectAfter := 3 * time.Minute + timeout := time.After(disconnectAfter) - <-time.After(disconnectAfter) - - defer func() { + select { + case <-timeout: logging.Info("Connection closed after", disconnectAfter) client.hub.unregister <- client client.conn.Close() - }() + } }() }