From 99dc02a15739e56afa0229779961883e9112bea5 Mon Sep 17 00:00:00 2001 From: kthatipally <99229993+kthatipally@users.noreply.github.com> Date: Tue, 29 Oct 2024 14:43:35 -0500 Subject: [PATCH] Add cancel context to NewGRPCClient --- provider/grpc/provider.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/provider/grpc/provider.go b/provider/grpc/provider.go index d621924d..d725e92a 100644 --- a/provider/grpc/provider.go +++ b/provider/grpc/provider.go @@ -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 } @@ -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 } @@ -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 { @@ -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) {