From e295f3afa54508b9e34a8e763208fe76c119aadc Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Wed, 4 Dec 2024 15:17:43 +0300 Subject: [PATCH] [#301] api: Call `dialer` for open connections too * If a client instance already sets `conn`, then `dialer` should be called for this `conn` anyway. `conn` may turn to invalidated state and thus we can check it with `dialer`. Signed-off-by: Airat Arifullin --- api/rpc/client/connect.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/api/rpc/client/connect.go b/api/rpc/client/connect.go index e22e0a6..57af64d 100644 --- a/api/rpc/client/connect.go +++ b/api/rpc/client/connect.go @@ -13,19 +13,17 @@ import ( var errInvalidEndpoint = errors.New("invalid endpoint options") func (c *Client) openGRPCConn(ctx context.Context, dialer func(ctx context.Context, cc grpcstd.ClientConnInterface) error) error { - if c.conn != nil { - return nil - } + if c.conn == nil { + if c.addr == "" { + return errInvalidEndpoint + } - if c.addr == "" { - return errInvalidEndpoint - } + var err error - var err error - - c.conn, err = grpcstd.NewClient(c.addr, c.grpcDialOpts...) - if err != nil { - return fmt.Errorf("gRPC new client: %w", err) + c.conn, err = grpcstd.NewClient(c.addr, c.grpcDialOpts...) + if err != nil { + return fmt.Errorf("gRPC new client: %w", err) + } } if dialer != nil {