From 887ab30b9028c8c8f178aa73dcac50366a681052 Mon Sep 17 00:00:00 2001 From: Liam Stanley Date: Mon, 21 Mar 2022 17:25:26 -0400 Subject: [PATCH] prevent potential hangup after ping timeout (fixes: #50) Signed-off-by: Liam Stanley --- conn.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/conn.go b/conn.go index 9adb17a..b691403 100644 --- a/conn.go +++ b/conn.go @@ -606,15 +606,16 @@ func (c *Client) pingLoop(ctx context.Context, errs chan error, wg *sync.WaitGro if time.Since(c.conn.lastPong) > c.Config.PingDelay+(60*time.Second) { // It's 60 seconds over what out ping delay is, connection // has probably dropped. - errs <- ErrTimedOut{ + err := ErrTimedOut{ TimeSinceSuccess: time.Since(c.conn.lastPong), LastPong: c.conn.lastPong, LastPing: c.conn.lastPing, Delay: c.Config.PingDelay, } - wg.Done() c.conn.mu.RUnlock() + errs <- err + wg.Done() return } c.conn.mu.RUnlock()