with the previous fix connection loss was not detected anymore, now using the ping method based on writing data which is more robust but may take a bit longer for connection loss to be detected.

This commit is contained in:
Erik Brakkee 2024-08-10 13:23:59 +02:00
parent ffcf7c8599
commit 346996e761

View File

@ -71,6 +71,8 @@ func GetUserLocation(r *http.Request) (*time.Location, error) {
}
func (session *WebSession) WriteNotifications(location *time.Location) {
timer := time.NewTicker(10 * time.Second)
defer timer.Stop()
for {
select {
case notification, ok := <-session.notifications:
@ -83,6 +85,12 @@ func (session *WebSession) WriteNotifications(location *time.Location) {
log.Printf("WS connection closed: %v", err)
return
}
case <-timer.C:
_, err := session.conn.Write(make([]byte, 0, 0))
if err != nil {
log.Printf("WS connection closed: %v", err)
return
}
}
}
}