Skip to content

Commit

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

Signed-off-by: Benjamin Wang <[email protected]>
  • Loading branch information
ahrtr committed Jan 17, 2025
1 parent c995d7f commit 8c456ea
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)

Check warning on line 866 in server/embed/etcd.go

View check run for this annotation

Codecov / codecov/patch

server/embed/etcd.go#L866

Added line #L866 was not covered by tests
go func(u url.URL, ln net.Listener) {
defer e.wg.Done()

Check warning on line 868 in server/embed/etcd.go

View check run for this annotation

Codecov / codecov/patch

server/embed/etcd.go#L868

Added line #L868 was not covered by tests
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 8c456ea

Please sign in to comment.