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 281f177
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 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,13 @@ func (c *Client) Sync(ctx context.Context) error {
eps = append(eps, m.ClientURLs...)
}
}
// The linearizable `MemberList` returned successfully, so the
// endpoints shouldn't be empty.
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 281f177

Please sign in to comment.