From cc47cf2439b7c4cd883f1814fd4b4b73237dc297 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Tue, 27 Feb 2018 14:50:08 +0200 Subject: [PATCH] Use fresh cluster state after sleeping --- cluster.go | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/cluster.go b/cluster.go index 783e27d..8b01a51 100644 --- a/cluster.go +++ b/cluster.go @@ -682,18 +682,23 @@ func (c *ClusterClient) Process(cmd Cmder) error { } func (c *ClusterClient) defaultProcess(cmd Cmder) error { - _, node, err := c.cmdSlotAndNode(cmd) - if err != nil { - cmd.setErr(err) - return err - } - + var node *clusterNode var ask bool for attempt := 0; attempt <= c.opt.MaxRedirects; attempt++ { if attempt > 0 { time.Sleep(c.retryBackoff(attempt)) } + if node == nil { + var err error + _, node, err = c.cmdSlotAndNode(cmd) + if err != nil { + cmd.setErr(err) + break + } + } + + var err error if ask { pipe := node.Client.Pipeline() _ = pipe.Process(NewCmd("ASKING")) @@ -717,9 +722,8 @@ func (c *ClusterClient) defaultProcess(cmd Cmder) error { } if internal.IsRetryableError(err, true) { - var nodeErr error - node, nodeErr = c.nodes.Random() - if nodeErr != nil { + node, err = c.nodes.Random() + if err != nil { break } continue @@ -731,20 +735,15 @@ func (c *ClusterClient) defaultProcess(cmd Cmder) error { if moved || ask { c.lazyReloadState() - var nodeErr error - node, nodeErr = c.nodes.GetOrCreate(addr) - if nodeErr != nil { + node, err = c.nodes.GetOrCreate(addr) + if err != nil { break } continue } if err == pool.ErrClosed { - _, node, err = c.cmdSlotAndNode(cmd) - if err != nil { - cmd.setErr(err) - break - } + node = nil continue }