From 6c0c8700e93dbb0d3399054ff9f7fd4221f44129 Mon Sep 17 00:00:00 2001 From: Xiaolong Chen Date: Sun, 21 Dec 2025 22:04:55 +0800 Subject: [PATCH] When the connection to a Sentinel times out, attempt to connect to other Sentinel Signed-off-by: Xiaolong Chen --- sentinel.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sentinel.go b/sentinel.go index 663f7b1ad..fe965322e 100644 --- a/sentinel.go +++ b/sentinel.go @@ -827,7 +827,7 @@ func (c *sentinelFailover) MasterAddr(ctx context.Context) (string, error) { if sentinel != nil { addr, err := c.getMasterAddr(ctx, sentinel) if err != nil { - if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { + if isContextError(ctx.Err()) { return "", err } // Continue on other errors @@ -845,7 +845,7 @@ func (c *sentinelFailover) MasterAddr(ctx context.Context) (string, error) { addr, err := c.getMasterAddr(ctx, c.sentinel) if err != nil { _ = c.closeSentinel() - if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { + if isContextError(ctx.Err()) { return "", err } // Continue on other errors @@ -930,7 +930,7 @@ func (c *sentinelFailover) replicaAddrs(ctx context.Context, useDisconnected boo if sentinel != nil { addrs, err := c.getReplicaAddrs(ctx, sentinel) if err != nil { - if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { + if isContextError(ctx.Err()) { return nil, err } // Continue on other errors @@ -948,7 +948,7 @@ func (c *sentinelFailover) replicaAddrs(ctx context.Context, useDisconnected boo addrs, err := c.getReplicaAddrs(ctx, c.sentinel) if err != nil { _ = c.closeSentinel() - if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { + if isContextError(ctx.Err()) { return nil, err } // Continue on other errors @@ -970,7 +970,7 @@ func (c *sentinelFailover) replicaAddrs(ctx context.Context, useDisconnected boo replicas, err := sentinel.Replicas(ctx, c.opt.MasterName).Result() if err != nil { _ = sentinel.Close() - if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { + if isContextError(ctx.Err()) { return nil, err } internal.Logger.Printf(ctx, "sentinel: Replicas master=%q failed: %s",