Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Add cancel context to NewGRPCClient (#720) #753

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading