diff --git a/pkg/topom/topom_stats.go b/pkg/topom/topom_stats.go index 429a89df7..9ee17273d 100644 --- a/pkg/topom/topom_stats.go +++ b/pkg/topom/topom_stats.go @@ -82,11 +82,13 @@ func (s *Topom) RefreshRedisStats(timeout time.Duration) (*sync2.Future, error) defer s.ha.redisp.PutClient(c) m, err := c.Info() if err != nil { + c.ShouldClose = true return nil, err } sentinel := redis.NewSentinel(s.config.ProductName, s.config.ProductAuth) p, err := sentinel.MastersAndSlavesClient(c) if err != nil { + c.ShouldClose = true return nil, err } return &RedisStats{Stats: m, Sentinel: p}, nil diff --git a/pkg/utils/redis/client.go b/pkg/utils/redis/client.go index 4ef8be235..a6b01ca45 100644 --- a/pkg/utils/redis/client.go +++ b/pkg/utils/redis/client.go @@ -30,6 +30,8 @@ type Client struct { Pipeline struct { Send, Recv uint64 } + + ShouldClose bool } func NewClientNoAuth(addr string, timeout time.Duration) (*Client, error) { @@ -48,6 +50,7 @@ func NewClient(addr string, auth string, timeout time.Duration) (*Client, error) return &Client{ conn: c, Addr: addr, Auth: auth, LastUse: time.Now(), Timeout: timeout, + ShouldClose: false, }, nil } @@ -57,6 +60,8 @@ func (c *Client) Close() error { func (c *Client) isRecyclable() bool { switch { + case c.ShouldClose: + return false case c.conn.Err() != nil: return false case c.Pipeline.Send != c.Pipeline.Recv: