From 2ddc1ef9e4883b7ea44baa02301b1009beac4943 Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Wed, 20 Nov 2024 20:18:41 +0100 Subject: [PATCH] move check for unresponsive clients to additional loops --- internal/websocket/broadcast.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/internal/websocket/broadcast.go b/internal/websocket/broadcast.go index 346808a..c4ed27a 100644 --- a/internal/websocket/broadcast.go +++ b/internal/websocket/broadcast.go @@ -22,17 +22,19 @@ func SendPermanentBroadCastMessage() { // Iterate over all connected clients and broadcast the message for _, client := range Clients { - if time.Now().Sub(client.LastPong) > 10*time.Second { - // Remove unresponsive client - client.Conn.Close() - delete(Clients, client.Conn.LocalAddr()) - helper.Logger.Info("Client timed out", "host", client.RealIP, "clients", len(Clients)) - } err := client.SendMessage(websocket.TextMessage, jsonMessage) if err != nil { helper.Logger.Info("Error broadcasting to client:", "msg", err, "host", client.RealIP, "clients", len(Clients)) } } + for _, client := range Clients { + if time.Now().Sub(client.LastPong) > (10 * time.Second) { + // Remove unresponsive client + client.Conn.Close() + delete(Clients, client.Conn.LocalAddr()) + helper.Logger.Info("Client timed out", "host", client.RealIP, "clients", len(Clients)) + } + } <-tick.C } }