Close additional leaked GPRC clients

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
pull/5270/head
Brad Davidson 2022-03-10 14:03:02 -08:00 committed by Brad Davidson
parent 1f7abe5dbb
commit 078da46532
2 changed files with 22 additions and 1 deletions

View File

@ -28,9 +28,13 @@ func Register(ctx context.Context, runtime *config.ControlRuntime, endpoints con
if err != nil { if err != nil {
return err return err
} }
h.etcdClient = cl h.etcdClient = cl
go func() {
<-ctx.Done()
h.etcdClient.Close()
}()
return nil return nil
} }

View File

@ -148,6 +148,11 @@ func (e *ETCD) SetControlConfig(ctx context.Context, config *config.Control) err
} }
e.client = client e.client = client
go func() {
<-ctx.Done()
e.client.Close()
}()
address, err := GetAdvertiseAddress(config.PrivateIP) address, err := GetAdvertiseAddress(config.PrivateIP)
if err != nil { if err != nil {
return err return err
@ -479,6 +484,11 @@ func (e *ETCD) Register(ctx context.Context, config *config.Control, handler htt
} }
e.client = client e.client = client
go func() {
<-ctx.Done()
e.client.Close()
}()
address, err := GetAdvertiseAddress(config.PrivateIP) address, err := GetAdvertiseAddress(config.PrivateIP)
if err != nil { if err != nil {
return nil, err return nil, err
@ -1098,6 +1108,11 @@ func (e *ETCD) preSnapshotSetup(ctx context.Context, config *config.Control) err
return err return err
} }
e.client = client e.client = client
go func() {
<-ctx.Done()
e.client.Close()
}()
} }
return nil return nil
} }
@ -1958,6 +1973,8 @@ func GetAPIServerURLsFromETCD(ctx context.Context, cfg *config.Control) ([]strin
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer cl.Close()
etcdResp, err := cl.KV.Get(ctx, AddressKey) etcdResp, err := cl.KV.Get(ctx, AddressKey)
if err != nil { if err != nil {
return nil, err return nil, err