From 1d16cc30701df0c2fc0823de1d04c9be17579f70 Mon Sep 17 00:00:00 2001 From: Thomas <9749173+uhthomas@users.noreply.github.com> Date: Mon, 18 Sep 2023 19:54:33 +0100 Subject: [PATCH] fix(pkg/stash): don't check status of all etcd endpoints on start (#1889) --- pkg/stash/with_etcd.go | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/pkg/stash/with_etcd.go b/pkg/stash/with_etcd.go index 1cd8d2f9..0d89424b 100644 --- a/pkg/stash/with_etcd.go +++ b/pkg/stash/with_etcd.go @@ -10,39 +10,21 @@ import ( "github.com/gomods/athens/pkg/storage" clientv3 "go.etcd.io/etcd/client/v3" "go.etcd.io/etcd/client/v3/concurrency" - "golang.org/x/sync/errgroup" ) // WithEtcd returns a distributed singleflight // using an etcd cluster. If it cannot connect, // to any of the endpoints, it will return an error. func WithEtcd(endpoints []string, checker storage.Checker) (Wrapper, error) { - const op errors.Op = "stash.WithEtcd" - ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) - defer cancel() c, err := clientv3.New(clientv3.Config{ Endpoints: endpoints, - DialTimeout: time.Second * 5, + DialTimeout: 5 * time.Second, }) if err != nil { - return nil, errors.E(op, err) - } - var eg errgroup.Group - for _, ep := range endpoints { - epStat := func(ep string) func() error { - return func() error { - _, err := c.Status(ctx, ep) - return err - } - }(ep) - eg.Go(epStat) - } - err = eg.Wait() - if err != nil { - return nil, errors.E(op, err) + return nil, errors.E("stash.WithEtcd", err) } return func(s Stasher) Stasher { - return &etcd{c, s, checker} + return &etcd{client: c, stasher: s, checker: checker} }, nil }