Skip to content

Commit d7ba255

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

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
@@ -445,6 +445,14 @@ func (n *clusterNode) SetLastLatencyMeasurement(t time.Time) {
445445
}
446446
}
447447

448+
func (n *clusterNode) Loading() bool {
449+
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
450+
defer cancel()
451+
452+
err := n.Client.Ping(ctx).Err()
453+
return err != nil && isLoadingError(err)
454+
}
455+
448456
//------------------------------------------------------------------------------
449457

450458
type clusterNodes struct {
@@ -754,7 +762,8 @@ func (c *clusterState) slotSlaveNode(slot int) (*clusterNode, error) {
754762
case 1:
755763
return nodes[0], nil
756764
case 2:
757-
if slave := nodes[1]; !slave.Failing() {
765+
slave := nodes[1]
766+
if !slave.Failing() && !slave.Loading() {
758767
return slave, nil
759768
}
760769
return nodes[0], nil
@@ -763,7 +772,7 @@ func (c *clusterState) slotSlaveNode(slot int) (*clusterNode, error) {
763772
for i := 0; i < 10; i++ {
764773
n := rand.Intn(len(nodes)-1) + 1
765774
slave = nodes[n]
766-
if !slave.Failing() {
775+
if !slave.Failing() && !slave.Loading() {
767776
return slave, nil
768777
}
769778
}

0 commit comments

Comments
 (0)