Skip to content

Commit

Permalink
Ensure all goroutines created by StartEtcd to complete before closing…
Browse files Browse the repository at this point in the history
… the errc

Signed-off-by: Benjamin Wang <[email protected]>
  • Loading branch information
ahrtr committed Jan 17, 2025
1 parent 979cbbe commit 0a5de14
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions server/embed/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,9 @@ func (e *Etcd) servePeers() {

// start peer servers in a goroutine
for _, pl := range e.Peers {
e.wg.Add(1)
go func(l *peerListener) {
defer e.wg.Done()
u := l.Addr().String()
e.cfg.logger.Info(
"serving peer traffic",
Expand Down Expand Up @@ -774,7 +776,9 @@ func (e *Etcd) serveClients() {

// start client servers in each goroutine
for _, sctx := range e.sctxs {
e.wg.Add(1)
go func(s *serveCtx) {
defer e.wg.Done()
e.errHandler(s.serve(e.Server, &e.cfg.ClientTLSInfo, mux, e.errHandler, e.grpcGatewayDial(splitHTTP), splitHTTP, gopts...))
}(sctx)
}
Expand Down Expand Up @@ -859,7 +863,9 @@ func (e *Etcd) serveMetrics() (err error) {
return err
}
e.metricsListeners = append(e.metricsListeners, ml)
e.wg.Add(1)
go func(u url.URL, ln net.Listener) {
defer e.wg.Done()
e.cfg.logger.Info(
"serving metrics",
zap.String("address", u.String()),
Expand All @@ -872,9 +878,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))
}
Expand Down

0 comments on commit 0a5de14

Please sign in to comment.