From bb141bffb89cfde45ffa58167781bf25bb5bf2a3 Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Thu, 21 Nov 2024 07:37:55 +0100 Subject: [PATCH] split ping sending and pong check --- internal/websocket/staleClients.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/websocket/staleClients.go b/internal/websocket/staleClients.go index bfa3de9..d7980ac 100644 --- a/internal/websocket/staleClients.go +++ b/internal/websocket/staleClients.go @@ -31,8 +31,14 @@ func RemoveStaleClients() { for range ticker.C { mu.Lock() for _, client := range Clients { - // send ping and check for last pong - if !sendPing(client) || isStale(client) { + // send ping + if !sendPing(client) { + client.Conn.Close() + delete(Clients, client.Conn.LocalAddr()) + } + + // check for last pong + if isStale(client) { client.Conn.Close() delete(Clients, client.Conn.LocalAddr()) }