From 4e4ab4adc6bfc38b96483f7550168583c8fff939 Mon Sep 17 00:00:00 2001 From: neza2017 Date: Wed, 30 Jun 2021 14:12:15 +0800 Subject: [PATCH] check if etcd is health before register session (#6215) Signed-off-by: yefu.chen --- internal/util/sessionutil/session_util.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/util/sessionutil/session_util.go b/internal/util/sessionutil/session_util.go index c922b7bef3..d8b71fabe5 100644 --- a/internal/util/sessionutil/session_util.go +++ b/internal/util/sessionutil/session_util.go @@ -65,6 +65,11 @@ func NewSession(ctx context.Context, metaRoot string, etcdEndpoints []string) *S if err != nil { return err } + ctx2, cancel2 := context.WithTimeout(session.ctx, 5*time.Second) + defer cancel2() + if _, err = etcdCli.Get(ctx2, "health"); err != nil { + return err + } session.etcdCli = etcdCli return nil }