From 729f03be0de1dfc1bb80e17f3c06be2dfffacba2 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 7 Oct 2023 19:16:27 +0200 Subject: [PATCH] fix: Reset timeout on successful Ping --- loop.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/loop.go b/loop.go index 91407d1..bfb128b 100644 --- a/loop.go +++ b/loop.go @@ -107,8 +107,12 @@ msgLoop: case <-time.After(l.party.keepAliveInterval()): // Send ping only when there was no write in the keepAliveInterval before if time.Since(l.hubConn.LastWriteStamp()) > l.party.keepAliveInterval() { - _ = l.hubConn.Ping() + if err = l.hubConn.Ping(); err != nil { + break pingLoop + } } + // A successful ping or Write shows us that the connection is alive. Reset the timeout + timeoutTicker.Reset(l.party.timeout()) // Don't break the pingLoop when keepAlive is over, it exists for this case case <-timeoutTicker.C: err = fmt.Errorf("timeout interval elapsed (%v)", l.party.timeout())