Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
etcdadm: Should close GRPC clients
Browse files Browse the repository at this point in the history
We should be closing these when we are done with the connection,
otherwise we leak goroutines.
  • Loading branch information
justinsb committed Feb 4, 2023
1 parent 503eb2b commit be7ccb5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ var infoCmd = &cobra.Command{
if err != nil {
log.Fatalf("[membership] Error requesting member information: %s", err)
}
defer client.Close()

ctx, cancel := context.WithTimeout(context.Background(), constants.DefaultEtcdRequestTimeout)
mresp, err := client.MemberList(ctx)
cancel()
Expand Down
2 changes: 2 additions & 0 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ func healthcheck() phase {
if err != nil {
return fmt.Errorf("error creating health endpoint client: %w", err)
}
defer client.Close()

ctx, cancel := context.WithTimeout(context.Background(), in.initSystem.StartupTimeout())
_, err = client.Get(ctx, constants.EtcdHealthCheckKey)
cancel()
Expand Down
2 changes: 2 additions & 0 deletions cmd/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ func membership() phase {
if err != nil {
return fmt.Errorf("error checking membership: %v", err)
}
defer client.Close()

ctx, cancel := context.WithTimeout(context.Background(), constants.DefaultEtcdRequestTimeout)
mresp, err := client.MemberList(ctx)
cancel()
Expand Down
2 changes: 2 additions & 0 deletions cmd/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ var resetCmd = &cobra.Command{
if err != nil {
log.Fatalf("[membership] Error checking membership: %v", err)
}
defer client.Close()

ctx, cancel := context.WithTimeout(context.Background(), constants.DefaultEtcdRequestTimeout)
mresp, err := client.MemberList(ctx)
cancel()
Expand Down
1 change: 1 addition & 0 deletions etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
)

// ClientForEndpoint returns an etcd client that will use the given etcd endpoint.
// Callers should Close() the returned connection after use.
func ClientForEndpoint(endpoint string, cfg *apis.EtcdAdmConfig) (*clientv3.Client, error) {
tlsInfo := transport.TLSInfo{
CertFile: cfg.EtcdctlCertFile,
Expand Down

0 comments on commit be7ccb5

Please sign in to comment.