diff --git a/cluster.go b/cluster.go index 5ba956a1..1895f467 100644 --- a/cluster.go +++ b/cluster.go @@ -92,8 +92,8 @@ type connrole struct { replica bool } -func newClusterClient(opt *ClientOption, connFn connFn) (client *clusterClient, err error) { - client = &clusterClient{ +func newClusterClient(opt *ClientOption, connFn connFn) (*clusterClient, error) { + client := &clusterClient{ cmd: cmds.NewBuilder(cmds.InitSlot), connFn: connFn, opt: opt, @@ -120,11 +120,11 @@ func newClusterClient(opt *ClientOption, connFn connFn) (client *clusterClient, return cc } - if err = client.init(); err != nil { + if err := client.init(); err != nil { return nil, err } - if err = client.refresh(context.Background()); err != nil { + if err := client.refresh(context.Background()); err != nil { return client, err } diff --git a/cluster_test.go b/cluster_test.go index 2d28a491..a1255755 100644 --- a/cluster_test.go +++ b/cluster_test.go @@ -4330,3 +4330,23 @@ func TestClusterShardsParsing(t *testing.T) { } }) } + +// https://github.com/redis/rueidis/issues/543 +func TestConnectToNonAvailableCluster(t *testing.T) { + var wg sync.WaitGroup + for i := 0; i < 4; i++ { + wg.Add(1) + go func() { + defer wg.Done() + for i := 0; i < 100; i++ { + _, err := NewClient(ClientOption{ + InitAddress: []string{"127.0.0.1:3000", "127.0.0.1:3001", "127.0.0.1:3002"}, + }) + if err == nil { + t.Errorf("expected connect error") + } + } + }() + } + wg.Wait() +}