Compare commits
2 commits
55f7ecae6b
...
6f355fe441
Author | SHA1 | Date | |
---|---|---|---|
6f355fe441 | |||
a98b4bc154 |
1 changed files with 3 additions and 4 deletions
|
@ -16,12 +16,10 @@ func RemoveStaleClients() {
|
||||||
for range ticker.C {
|
for range ticker.C {
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
for _, client := range Clients {
|
for _, client := range Clients {
|
||||||
ping := sendPing(client)
|
if !sendPing(client) || isStale(client) {
|
||||||
stale := isStale(client)
|
|
||||||
if !ping || stale {
|
|
||||||
client.Conn.Close()
|
client.Conn.Close()
|
||||||
delete(Clients, client.Conn.LocalAddr())
|
delete(Clients, client.Conn.LocalAddr())
|
||||||
helper.Logger.Info("Removed stale client", "host", client.RealIP, "lastPong", client.LastPong.Format("RFC3339"))
|
helper.Logger.Info("Removed stale client", "host", client.RealIP, "lastPong", client.LastPong)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
|
@ -33,6 +31,7 @@ func sendPing(client *models.WebsocketClient) bool {
|
||||||
err := client.Conn.WriteMessage(websocket.PingMessage, nil)
|
err := client.Conn.WriteMessage(websocket.PingMessage, nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
helper.Logger.Debug("ping failed", "host", client.RealIP)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue