Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <[email protected]>
  • Loading branch information
lhy1024 committed Jul 4, 2023
1 parent 78fe096 commit 1e612e0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
1 change: 1 addition & 0 deletions pkg/election/leadership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func TestLeadership(t *testing.T) {
re.NoError(lease1.Close())
re.NoError(lease2.Close())
}

func TestExitWatch(t *testing.T) {
re := require.New(t)
leaderKey := "/test_leader"
Expand Down
7 changes: 3 additions & 4 deletions pkg/utils/etcdutil/etcdutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ func CreateEtcdClient(tlsConfig *tls.Config, acURLs []url.URL) (*clientv3.Client
for {
select {
case <-client.Ctx().Done():
log.Info("[etcd client] etcd client is closed, exit health check goroutine")
return
case <-ticker.C:
usedEps := client.Endpoints()
Expand Down Expand Up @@ -302,6 +303,7 @@ func CreateEtcdClient(tlsConfig *tls.Config, acURLs []url.URL) (*clientv3.Client
for {
select {
case <-client.Ctx().Done():
log.Info("[etcd client] etcd client is closed, exit update endpoint goroutine")
return
case <-ticker.C:
eps := syncUrls(client)
Expand Down Expand Up @@ -371,6 +373,7 @@ func (checker *healthyChecker) update(eps []string) {
if time.Since(lastHealthy) > etcdServerDisconnectedTimeout {
// try to update client to trigger reconnect
checker.addClient(ep, lastHealthy)
client.(*healthyClient).Close()
}
continue
}
Expand All @@ -394,15 +397,11 @@ func syncUrls(client *clientv3.Client) []string {
// See https://github.com/etcd-io/etcd/blob/85b640cee793e25f3837c47200089d14a8392dc7/clientv3/client.go#L170-L183
ctx, cancel := context.WithTimeout(clientv3.WithRequireLeader(client.Ctx()), DefaultRequestTimeout)
defer cancel()
now := time.Now()
mresp, err := client.MemberList(ctx)
if err != nil {
log.Error("[etcd client] failed to list members", errs.ZapError(err))
return []string{}
}
if time.Since(now) > defaultEtcdClientTimeout {
log.Warn("[etcd client] sync etcd members slow", zap.Duration("cost", time.Since(now)), zap.Int("members", len(mresp.Members)))
}
var eps []string
for _, m := range mresp.Members {
if len(m.Name) != 0 && !m.IsLearner {
Expand Down

0 comments on commit 1e612e0

Please sign in to comment.