From 8a04a8928a6571b744fda8e4ca70565ef1ccad34 Mon Sep 17 00:00:00 2001 From: dave vader <48764154+plyr4@users.noreply.github.com> Date: Wed, 14 Aug 2024 09:46:52 -0500 Subject: [PATCH] enhance: surface redis ping errors (#1165) --- queue/redis/ping.go | 3 +-- queue/redis/redis.go | 7 +++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/queue/redis/ping.go b/queue/redis/ping.go index 57d97a901..6a0a8b4b4 100644 --- a/queue/redis/ping.go +++ b/queue/redis/ping.go @@ -4,7 +4,6 @@ package redis import ( "context" - "fmt" ) // Ping contacts the queue to test its connection. @@ -13,7 +12,7 @@ func (c *client) Ping(ctx context.Context) error { err := c.Redis.Ping(ctx).Err() if err != nil { c.Logger.Debugf("unable to ping Redis queue.") - return fmt.Errorf("unable to establish connection to Redis queue") + return err } return nil diff --git a/queue/redis/redis.go b/queue/redis/redis.go index 88b962c00..e8ec6c6e4 100644 --- a/queue/redis/redis.go +++ b/queue/redis/redis.go @@ -9,6 +9,7 @@ import ( "time" "github.com/alicebob/miniredis/v2" + "github.com/pkg/errors" "github.com/redis/go-redis/v9" "github.com/sirupsen/logrus" @@ -151,9 +152,10 @@ func failoverFromOptions(source *redis.Options) *redis.FailoverOptions { // we try to set it up. func pingQueue(c *client) error { // attempt 10 times + var err error for i := 0; i < 10; i++ { // send ping request to client - err := c.Redis.Ping(context.Background()).Err() + err = c.Redis.Ping(context.Background()).Err() if err != nil { c.Logger.Debugf("unable to ping Redis queue. Retrying in %v", time.Duration(i)*time.Second) time.Sleep(1 * time.Second) @@ -164,7 +166,8 @@ func pingQueue(c *client) error { return nil } - return fmt.Errorf("unable to establish connection to Redis queue") + // capture last seen non-nil error + return errors.Wrap(err, "unable to establish connection to Redis queue") } // NewTest returns a Queue implementation that