From a29c1a1bd9124af4bb7438a4b75f702d2738a0d8 Mon Sep 17 00:00:00 2001 From: Benjamin Wang Date: Mon, 24 Jun 2024 10:05:48 +0100 Subject: [PATCH] add verification on client.Sync to ensure the returned endpoints never empty Signed-off-by: Benjamin Wang --- client/v3/client.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/client/v3/client.go b/client/v3/client.go index e6d2ae386758..ca416198fd6c 100644 --- a/client/v3/client.go +++ b/client/v3/client.go @@ -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" @@ -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