From d0d396f558bfa1196617b193de93461f9ec06f7e Mon Sep 17 00:00:00 2001 From: sabevzenko Date: Fri, 29 Sep 2023 16:20:18 +0300 Subject: [PATCH] grpc graceful shotdown on Bind grpc graceful shotdown on Bind --- components/guns/grpc/core.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/guns/grpc/core.go b/components/guns/grpc/core.go index 30f26f9b8..61fb13b09 100644 --- a/components/guns/grpc/core.go +++ b/components/guns/grpc/core.go @@ -125,7 +125,7 @@ func NewGun(conf GunConfig) *Gun { func (g *Gun) Bind(aggr core.Aggregator, deps core.GunDeps) error { conn, err := makeGRPCConnect(g.conf.Target, g.conf.TLS, g.conf.DialOptions) if err != nil { - log.Fatalf("FATAL: grpc.Dial failed\n %s\n", err) + return fmt.Errorf("makeGRPCConnect fail %w", err) } g.client = conn g.aggr = aggr @@ -223,15 +223,15 @@ func makeGRPCConnect(target string, isTLS bool, dialOptions grpcDialOptions) (co if dialOptions.Timeout != 0 { timeout = dialOptions.Timeout } - opts = append(opts, grpc.WithTimeout(timeout)) opts = append(opts, grpc.WithUserAgent("load test, pandora universal grpc shooter")) if dialOptions.Authority != "" { opts = append(opts, grpc.WithAuthority(dialOptions.Authority)) } - conn, err = grpc.Dial(target, opts...) - return + ctx, cncl := context.WithTimeout(context.Background(), timeout) + defer cncl() + return grpc.DialContext(ctx, target, opts...) } func convertGrpcStatus(err error) int {