diff --git a/server/embed/serve.go b/server/embed/serve.go index a73ba58b1b5..daa65937523 100644 --- a/server/embed/serve.go +++ b/server/embed/serve.go @@ -102,6 +102,9 @@ func (sctx *serveCtx) serve( ) (err error) { logger := defaultLog.New(io.Discard, "etcdhttp", 0) + // Make sure serversC is closed even if we prematurely exit the function. + defer close(sctx.serversC) + select { case <-s.StoppingNotify(): return errors.New("server is stopping") @@ -121,8 +124,6 @@ func (sctx *serveCtx) serve( servElection := v3election.NewElectionServer(v3c) servLock := v3lock.NewLockServer(v3c) - // Make sure serversC is closed even if we prematurely exit the function. - defer close(sctx.serversC) var gwmux *gw.ServeMux if s.Cfg.EnableGRPCGateway { // GRPC gateway connects to grpc server via connection provided by grpc dial.