From 7e815e9b7114c26939d89d40baeadb0fdfd2d08b Mon Sep 17 00:00:00 2001 From: Joshua Zhang Date: Thu, 16 Jan 2025 05:08:29 +0000 Subject: [PATCH] Avoid racing in closing Etcd.errc channel Signed-off-by: Joshua Zhang --- server/embed/etcd.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/server/embed/etcd.go b/server/embed/etcd.go index 4018a14d409..8a5a439d1d4 100644 --- a/server/embed/etcd.go +++ b/server/embed/etcd.go @@ -872,9 +872,6 @@ func (e *Etcd) serveMetrics() (err error) { } func (e *Etcd) errHandler(err error) { - e.wg.Add(1) - defer e.wg.Done() - if err != nil { e.GetLogger().Error("setting up serving from embedded etcd failed.", zap.Error(err)) } @@ -883,6 +880,10 @@ func (e *Etcd) errHandler(err error) { return default: } + + e.wg.Add(1) + defer e.wg.Done() + select { case <-e.stopc: case e.errc <- err: