Skip to content

Commit

Permalink
Avoid deadlock in etcd.Close when stopping during bootstrapping
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Zhang <[email protected]>
  • Loading branch information
joshuazh-x committed Jan 7, 2025
1 parent fce823a commit 76a9777
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions server/embed/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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.
Expand Down

0 comments on commit 76a9777

Please sign in to comment.