Skip to content

Commit

Permalink
Close all listeners firstly, afterwards close the server
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Wang <[email protected]>
  • Loading branch information
ahrtr committed Jan 18, 2025
1 parent 9dd4d93 commit 3fa96c8
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions server/embed/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,19 +411,6 @@ func (e *Etcd) Close() {
close(e.stopc)
})

// close client requests with request timeout
timeout := 2 * time.Second
if e.Server != nil {
timeout = e.Server.Cfg.ReqTimeout()
}
for _, sctx := range e.sctxs {
for ss := range sctx.serversC {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
stopServers(ctx, ss)
cancel()
}
}

for _, sctx := range e.sctxs {
sctx.cancel()
}
Expand All @@ -443,11 +430,6 @@ func (e *Etcd) Close() {
e.tracingExporterShutdown()
}

// close rafthttp transports
if e.Server != nil {
e.Server.Stop()
}

// close all idle connections in peer handler (wait up to 1-second)
for i := range e.Peers {
if e.Peers[i] != nil && e.Peers[i].close != nil {
Expand All @@ -456,6 +438,25 @@ func (e *Etcd) Close() {
cancel()
}
}

// close client requests with request timeout
timeout := 2 * time.Second
if e.Server != nil {
timeout = e.Server.Cfg.ReqTimeout()
}
for _, sctx := range e.sctxs {
for ss := range sctx.serversC {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
stopServers(ctx, ss)
cancel()
}
}

// close rafthttp transports
if e.Server != nil {
e.Server.Stop()
}

if e.errc != nil {
e.wg.Wait()
close(e.errc)
Expand Down

0 comments on commit 3fa96c8

Please sign in to comment.