Fix 2 sources of leaked memory: embed server HTTP & v3_snapshot.leasser.

This commit is contained in:
Piotr Tabor
2021-03-16 22:20:00 +01:00
parent a57e967d84
commit 18382aa234
2 changed files with 7 additions and 11 deletions

View File

@@ -386,18 +386,14 @@ func (e *Etcd) Close() {
}
func stopServers(ctx context.Context, ss *servers) {
shutdownNow := func() {
// first, close the http.Server
ss.http.Shutdown(ctx)
// then close grpc.Server; cancels all active RPCs
ss.grpc.Stop()
}
// first, close the http.Server
ss.http.Shutdown(ctx)
// do not grpc.Server.GracefulStop with TLS enabled etcd server
// See https://github.com/grpc/grpc-go/issues/1384#issuecomment-317124531
// and https://github.com/etcd-io/etcd/issues/8916
if ss.secure {
shutdownNow()
ss.grpc.Stop()
return
}
@@ -415,7 +411,7 @@ func stopServers(ctx context.Context, ss *servers) {
case <-ctx.Done():
// took too long, manually close open transports
// e.g. watch streams
shutdownNow()
ss.grpc.Stop()
// concurrent GracefulStop should be interrupted
<-ch