[#117] rpc: Allow to specify custom gRPC dialer
All checks were successful
DCO action / DCO (pull_request) Successful in 47s
Tests and linters / Tests with -race (pull_request) Successful in 1m19s
Tests and linters / Tests (pull_request) Successful in 1m30s
Tests and linters / Lint (pull_request) Successful in 3m40s

After grpc upgrade there is no DialContext call.
So connection is not actually established after created.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2024-09-13 17:18:53 +03:00
parent c9782cf3ef
commit 6a81f3d404
4 changed files with 25 additions and 10 deletions

View file

@ -12,7 +12,7 @@ import (
var errInvalidEndpoint = errors.New("invalid endpoint options")
func (c *Client) openGRPCConn(ctx context.Context) error {
func (c *Client) openGRPCConn(ctx context.Context, dialer func(ctx context.Context, cc grpcstd.ClientConnInterface) error) error {
if c.conn != nil {
return nil
}
@ -21,15 +21,20 @@ func (c *Client) openGRPCConn(ctx context.Context) error {
return errInvalidEndpoint
}
dialCtx, cancel := context.WithTimeout(ctx, c.dialTimeout)
var err error
c.conn, err = grpcstd.DialContext(dialCtx, c.addr, c.grpcDialOpts...)
cancel()
c.conn, err = grpcstd.NewClient(c.addr, c.grpcDialOpts...)
if err != nil {
return fmt.Errorf("gRPC dial: %w", err)
return fmt.Errorf("gRPC new client: %w", err)
}
if dialer != nil {
ctx, cancel := context.WithTimeout(ctx, c.dialTimeout)
defer cancel()
if err := dialer(ctx, c.conn); err != nil {
return fmt.Errorf("gRPC dial: %w", err)
}
}
return nil