From daf101bd7905b61ae654bc88ec1163be6914979e Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Tue, 9 Oct 2018 10:52:30 +0300 Subject: [PATCH] Fix nil ping error --- pubsub.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pubsub.go b/pubsub.go index b91972a..0afb47c 100644 --- a/pubsub.go +++ b/pubsub.go @@ -1,6 +1,7 @@ package redis import ( + "errors" "fmt" "sync" "time" @@ -10,6 +11,8 @@ import ( "github.com/go-redis/redis/internal/proto" ) +var errPingTimeout = errors.New("redis: ping timeout") + // PubSub implements Pub/Sub commands bas described in // http://redis.io/topics/pubsub. Message receiving is NOT safe // for concurrent use by multiple goroutines. @@ -438,7 +441,6 @@ func (c *PubSub) initChannel() { timer.Stop() healthy := true - var pingErr error for { timer.Reset(timeout) select { @@ -448,10 +450,13 @@ func (c *PubSub) initChannel() { <-timer.C } case <-timer.C: - pingErr = c.Ping() + pingErr := c.Ping() if healthy { healthy = false } else { + if pingErr == nil { + pingErr = errPingTimeout + } c.mu.Lock() c._reconnect(pingErr) c.mu.Unlock()