Skip to content

Commit

Permalink
Add cancel context to NewGRPCClient
Browse files Browse the repository at this point in the history
  • Loading branch information
kthatipally committed Oct 29, 2024
1 parent efb7857 commit 99dc02a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions provider/grpc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ import (
)

type grpcProvider struct {
Client pb.ProviderServiceClient
log logr.Logger
ctx context.Context
conn *grpc.ClientConn
config provider.Config
Client pb.ProviderServiceClient
log logr.Logger
ctx context.Context
conn *grpc.ClientConn
config provider.Config
cancelCmd context.CancelFunc

serviceClients []provider.ServiceClient
}
Expand All @@ -39,7 +40,8 @@ var _ provider.InternalProviderClient = &grpcProvider{}
func NewGRPCClient(config provider.Config, log logr.Logger) (provider.InternalProviderClient, error) {
log = log.WithName(config.Name)
log = log.WithValues("provider", "grpc")
conn, out, err := start(context.Background(), config)
ctxCmd, cancelCmd := context.WithCancel(context.Background())
conn, out, err := start(ctxCmd, config)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -71,6 +73,7 @@ func NewGRPCClient(config provider.Config, log logr.Logger) (provider.InternalPr
ctx: refCltCtx,
conn: conn,
config: config,
cancelCmd: cancelCmd,
serviceClients: []provider.ServiceClient{},
}
if out != nil {
Expand Down Expand Up @@ -239,6 +242,7 @@ func (g *grpcProvider) Stop() {
c.Stop()
}
g.conn.Close()
g.cancelCmd()
}

func start(ctx context.Context, config provider.Config) (*grpc.ClientConn, io.ReadCloser, error) {
Expand Down

0 comments on commit 99dc02a

Please sign in to comment.