From 63e3bc58c7d21783115fa0efc58ee6e09012b337 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Tue, 15 Aug 2017 10:12:43 +0300 Subject: [PATCH] Retry cluster down errors --- cluster.go | 2 +- cluster_test.go | 8 ++++---- internal/{errors.go => error.go} | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) rename internal/{errors.go => error.go} (88%) diff --git a/cluster.go b/cluster.go index a8695c32..647a25be 100644 --- a/cluster.go +++ b/cluster.go @@ -583,7 +583,7 @@ func (c *ClusterClient) Process(cmd Cmder) error { } // On network errors try random node. - if internal.IsRetryableError(err) { + if internal.IsRetryableError(err) || internal.IsClusterDownError(err) { node, err = c.nodes.Random() if err != nil { cmd.setErr(err) diff --git a/cluster_test.go b/cluster_test.go index 0176c685..91b9e80e 100644 --- a/cluster_test.go +++ b/cluster_test.go @@ -700,14 +700,14 @@ var _ = Describe("ClusterClient timeout", func() { testTimeout() }) - Context("network timeout", func() { + Context("ClientPause timeout", func() { const pause = time.Second BeforeEach(func() { opt := redisClusterOptions() - opt.ReadTimeout = 100 * time.Millisecond - opt.WriteTimeout = 100 * time.Millisecond - opt.MaxRedirects = 1 + opt.ReadTimeout = pause / 10 + opt.WriteTimeout = pause / 10 + opt.MaxRedirects = -1 client = cluster.clusterClient(opt) err := client.ForEachNode(func(client *redis.Client) error { diff --git a/internal/errors.go b/internal/error.go similarity index 88% rename from internal/errors.go rename to internal/error.go index c93e0081..90f6503a 100644 --- a/internal/errors.go +++ b/internal/error.go @@ -67,9 +67,9 @@ func IsMovedError(err error) (moved bool, ask bool, addr string) { } func IsLoadingError(err error) bool { - return strings.HasPrefix(err.Error(), "LOADING") + return strings.HasPrefix(err.Error(), "LOADING ") } -func IsExecAbortError(err error) bool { - return strings.HasPrefix(err.Error(), "EXECABORT") +func IsClusterDownError(err error) bool { + return strings.HasPrefix(err.Error(), "CLUSTERDOWN ") }