Skip to content

Commit 94c1473

Browse files
ofekshenawandyakov
andcommitted
fix: prevent routing reads to loading slave nodes (redis#3370)
Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com>
1 parent ad6f12f commit 94c1473

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

osscluster.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,14 @@ func (n *clusterNode) SetLastLatencyMeasurement(t time.Time) {
454454
}
455455
}
456456

457+
func (n *clusterNode) Loading() bool {
458+
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
459+
defer cancel()
460+
461+
err := n.Client.Ping(ctx).Err()
462+
return err != nil && isLoadingError(err)
463+
}
464+
457465
//------------------------------------------------------------------------------
458466

459467
type clusterNodes struct {
@@ -763,7 +771,8 @@ func (c *clusterState) slotSlaveNode(slot int) (*clusterNode, error) {
763771
case 1:
764772
return nodes[0], nil
765773
case 2:
766-
if slave := nodes[1]; !slave.Failing() {
774+
slave := nodes[1]
775+
if !slave.Failing() && !slave.Loading() {
767776
return slave, nil
768777
}
769778
return nodes[0], nil
@@ -772,7 +781,7 @@ func (c *clusterState) slotSlaveNode(slot int) (*clusterNode, error) {
772781
for i := 0; i < 10; i++ {
773782
n := rand.Intn(len(nodes)-1) + 1
774783
slave = nodes[n]
775-
if !slave.Failing() {
784+
if !slave.Failing() && !slave.Loading() {
776785
return slave, nil
777786
}
778787
}

0 commit comments

Comments
 (0)