Skip to content

Commit

Permalink
add verification on client.Sync to ensure the returned endpoints neve…
Browse files Browse the repository at this point in the history
…r empty

Signed-off-by: Benjamin Wang <[email protected]>
  • Loading branch information
ahrtr committed Jun 24, 2024
1 parent 9314ef7 commit a29c1a1
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions client/v3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
"go.etcd.io/etcd/api/v3/version"
"go.etcd.io/etcd/client/pkg/v3/logutil"
"go.etcd.io/etcd/client/pkg/v3/verify"
"go.etcd.io/etcd/client/v3/credentials"
"go.etcd.io/etcd/client/v3/internal/endpoint"
"go.etcd.io/etcd/client/v3/internal/resolver"
Expand Down Expand Up @@ -194,6 +195,11 @@ func (c *Client) Sync(ctx context.Context) error {
eps = append(eps, m.ClientURLs...)
}
}
verify.Verify(func() {
if len(eps) == 0 {
panic("empty endpoints returned from etcd cluster")
}
})
c.SetEndpoints(eps...)
c.lg.Debug("set etcd endpoints by autoSync", zap.Strings("endpoints", eps))
return nil
Expand Down

0 comments on commit a29c1a1

Please sign in to comment.