websocket api: fix websocket connection timeout handling

This commit is contained in:
in-void 2023-03-07 23:50:04 +01:00
parent b8dd4c167a
commit 3fb3b1b794

View File

@ -76,15 +76,15 @@ func (h *ConnectionHandler) serveWs(hub *Hub, w http.ResponseWriter, r *http.Req
go client.readPump() go client.readPump()
go func() { go func() {
disconnectAfter := time.Duration(3) * time.Minute disconnectAfter := 3 * time.Minute
timeout := time.After(disconnectAfter)
<-time.After(disconnectAfter) select {
case <-timeout:
defer func() {
logging.Info("Connection closed after", disconnectAfter) logging.Info("Connection closed after", disconnectAfter)
client.hub.unregister <- client client.hub.unregister <- client
client.conn.Close() client.conn.Close()
}() }
}() }()
} }