From 2b89b7e7982cd13f61489d526c4ecf6f811beedb Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 3 Oct 2022 13:20:08 +0400 Subject: [PATCH] [#419] rpc/client: Block until client connection is up In previous implementation `Client` didn't block until the connection is up on dial stage. This caused the dial timeout to have no effect. Provide `WithBlock` dial option to `DialContext` call in `openGRPCConn` method. From now `Client` blocks for configured timeout until the connection is up. Signed-off-by: Leonard Lyubich --- rpc/client/connect.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rpc/client/connect.go b/rpc/client/connect.go index 18134c48..a5403e33 100644 --- a/rpc/client/connect.go +++ b/rpc/client/connect.go @@ -49,10 +49,16 @@ func (c *Client) openGRPCConn() error { dialCtx, cancel := context.WithTimeout(context.Background(), c.dialTimeout) var err error - c.conn, err = grpcstd.DialContext(dialCtx, c.addr, grpcstd.WithTransportCredentials(creds)) + c.conn, err = grpcstd.DialContext(dialCtx, c.addr, + grpcstd.WithTransportCredentials(creds), + grpcstd.WithBlock(), + ) cancel() + if err != nil { + return fmt.Errorf("open gRPC client connection: %w", err) + } - return err + return nil } // ParseURI parses s as address and returns a host and a flag