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 29ddb6ce00
commit 2fe2be0b9a

View File

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