Skip to content

Commit

Permalink
Merge pull request etcd-io#18220 from ahrtr/ep__sync_verify_20240624
Browse files Browse the repository at this point in the history
Add verification on `client.Sync` to ensure the returned endpoints never empty
  • Loading branch information
ahrtr authored Jun 24, 2024
2 parents 9314ef7 + 281f177 commit b96b6ba
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 b96b6ba

Please sign in to comment.