From b602e9472b9d7cc6d9915b8c133c727e003bf8b6 Mon Sep 17 00:00:00 2001 From: Scott Weber Date: Wed, 1 May 2024 09:17:15 +0100 Subject: [PATCH] Make Signal ping kill and rebuild websocket if it takes more than 20s (#507) --- pkg/signalmeow/web/signalwebsocket.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/signalmeow/web/signalwebsocket.go b/pkg/signalmeow/web/signalwebsocket.go index 40e43e46..0b97b8a7 100644 --- a/pkg/signalmeow/web/signalwebsocket.go +++ b/pkg/signalmeow/web/signalwebsocket.go @@ -292,9 +292,12 @@ func (s *SignalWebsocket) connectLoop( for { select { case <-ticker.C: - err := ws.Ping(loopCtx) + pingCtx, cancel := context.WithTimeout(loopCtx, 20*time.Second) + err := ws.Ping(pingCtx) + cancel() if err != nil { - loopCancel(fmt.Errorf("error sending keepalive: %w", err)) + log.Err(err).Msg("Error pinging") + loopCancel(err) return } log.Debug().Msg("Sent keepalive")