From 8a5db20d32852093cae53e08ea62fabf4b22f22c Mon Sep 17 00:00:00 2001 From: Pavlov Aleksey Date: Thu, 6 Aug 2020 18:04:04 +0300 Subject: [PATCH] fix nil node dereference when use RouteByLatency in cluster --- cluster.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cluster.go b/cluster.go index 78d5def5..346d675f 100644 --- a/cluster.go +++ b/cluster.go @@ -564,7 +564,11 @@ func (c *clusterState) slotClosestNode(slot int) (*clusterNode, error) { node = n } } - return node, nil + if node != nil { + return node, nil + } + // If all nodes are failing - return random node + return c.nodes.Random() } func (c *clusterState) slotRandomNode(slot int) (*clusterNode, error) {