update stale logic to always execute ping and stale check

This commit is contained in:
Sebastian Mark 2024-11-21 19:35:05 +01:00
parent 7820d2acf0
commit 55f7ecae6b

View file

@ -16,10 +16,12 @@ func RemoveStaleClients() {
for range ticker.C {
mu.Lock()
for _, client := range Clients {
if sendPing(client) && !isStale(client) {
ping := sendPing(client)
stale := isStale(client)
if !ping || stale {
client.Conn.Close()
delete(Clients, client.Conn.LocalAddr())
helper.Logger.Info("Removed stale client", "host", client.RealIP, "lastPong", client.LastPong)
helper.Logger.Info("Removed stale client", "host", client.RealIP, "lastPong", client.LastPong.Format("RFC3339"))
}
}
mu.Unlock()