diff --git a/client/client.go b/client/client.go index 9047401a2f3..480b61dbfc4 100644 --- a/client/client.go +++ b/client/client.go @@ -206,15 +206,18 @@ func (c *client) updateURLs(members []*pdpb.Member) { for _, url := range urls { urlsMap[url] = struct{}{} } - needUpdate := false + containsOldURLs := true for _, url := range c.urls { if _, ok := urlsMap[url]; !ok { - needUpdate = true + containsOldURLs = false } } - if !needUpdate { + + // the url list is same. + if len(urls) == len(c.urls) && containsOldURLs { return } + log.Info("[pd] update member urls", zap.Strings("old-urls", c.urls), zap.Strings("new-urls", urls)) c.urls = urls } diff --git a/client/client_test.go b/client/client_test.go index 580f5c48f8a..5d5113d6bfc 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -500,6 +500,7 @@ func (s *testClientDialOptionSuite) TestGRPCDialOption(c *C) { start := time.Now() ctx, cancel := context.WithTimeout(context.TODO(), 100*time.Millisecond) defer cancel() + // nolint _, err := NewClientWithContext(ctx, []string{"localhost:8080"}, SecurityOption{}, WithGRPCDialOptions(grpc.WithBlock(), grpc.WithTimeout(time.Second))) c.Assert(err, NotNil) c.Assert(time.Since(start), Greater, 800*time.Millisecond)