Close additional leaked GPRC clients

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
This commit is contained in:
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 {
return err
}
h.etcdClient = cl
go func() {
<-ctx.Done()
h.etcdClient.Close()
}()
return nil
}

View File

@ -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