From 078da465329226d33d00dc46235e9c71f92e39e0 Mon Sep 17 00:00:00 2001 From: Brad Davidson Date: Thu, 10 Mar 2022 14:03:02 -0800 Subject: [PATCH] Close additional leaked GPRC clients Signed-off-by: Brad Davidson --- pkg/apiaddresses/controller.go | 6 +++++- pkg/etcd/etcd.go | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pkg/apiaddresses/controller.go b/pkg/apiaddresses/controller.go index d1609d7718..4d36bcae41 100644 --- a/pkg/apiaddresses/controller.go +++ b/pkg/apiaddresses/controller.go @@ -28,9 +28,13 @@ func Register(ctx context.Context, runtime *config.ControlRuntime, endpoints con if err != nil { return err } - h.etcdClient = cl + go func() { + <-ctx.Done() + h.etcdClient.Close() + }() + return nil } diff --git a/pkg/etcd/etcd.go b/pkg/etcd/etcd.go index ebfe93e294..2850ece0f5 100644 --- a/pkg/etcd/etcd.go +++ b/pkg/etcd/etcd.go @@ -148,6 +148,11 @@ func (e *ETCD) SetControlConfig(ctx context.Context, config *config.Control) err } e.client = client + go func() { + <-ctx.Done() + e.client.Close() + }() + address, err := GetAdvertiseAddress(config.PrivateIP) if err != nil { return err @@ -479,6 +484,11 @@ func (e *ETCD) Register(ctx context.Context, config *config.Control, handler htt } e.client = client + go func() { + <-ctx.Done() + e.client.Close() + }() + address, err := GetAdvertiseAddress(config.PrivateIP) if err != nil { return nil, err @@ -1098,6 +1108,11 @@ func (e *ETCD) preSnapshotSetup(ctx context.Context, config *config.Control) err return err } e.client = client + + go func() { + <-ctx.Done() + e.client.Close() + }() } return nil } @@ -1958,6 +1973,8 @@ func GetAPIServerURLsFromETCD(ctx context.Context, cfg *config.Control) ([]strin if err != nil { return nil, err } + defer cl.Close() + etcdResp, err := cl.KV.Get(ctx, AddressKey) if err != nil { return nil, err