[#9999] pool: Replace deprecated DialContext

`Healthcheck` request performed after client creation, so no extra RPC required.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2024-09-16 14:35:24 +03:00
parent 5a84fe8ac1
commit c648fbb543

View file

@ -43,7 +43,7 @@ func (c *treeClient) dial(ctx context.Context) error {
} }
var err error var err error
if c.conn, c.service, err = dialClient(ctx, c.address, c.opts...); err != nil { if c.conn, c.service, err = createClient(c.address, c.opts...); err != nil {
return err return err
} }
@ -61,7 +61,7 @@ func (c *treeClient) redialIfNecessary(ctx context.Context) (healthHasChanged bo
defer c.mu.Unlock() defer c.mu.Unlock()
if c.conn == nil { if c.conn == nil {
if c.conn, c.service, err = dialClient(ctx, c.address, c.opts...); err != nil { if c.conn, c.service, err = createClient(c.address, c.opts...); err != nil {
return false, err return false, err
} }
} }
@ -77,7 +77,7 @@ func (c *treeClient) redialIfNecessary(ctx context.Context) (healthHasChanged bo
return !wasHealthy, nil return !wasHealthy, nil
} }
func dialClient(ctx context.Context, addr string, clientOptions ...grpc.DialOption) (*grpc.ClientConn, grpcService.TreeServiceClient, error) { func createClient(addr string, clientOptions ...grpc.DialOption) (*grpc.ClientConn, grpcService.TreeServiceClient, error) {
host, tlsEnable, err := apiClient.ParseURI(addr) host, tlsEnable, err := apiClient.ParseURI(addr)
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("parse address: %w", err) return nil, nil, fmt.Errorf("parse address: %w", err)
@ -93,9 +93,9 @@ func dialClient(ctx context.Context, addr string, clientOptions ...grpc.DialOpti
// the order is matter, we want client to be able to overwrite options. // the order is matter, we want client to be able to overwrite options.
opts := append(options, clientOptions...) opts := append(options, clientOptions...)
conn, err := grpc.DialContext(ctx, host, opts...) conn, err := grpc.NewClient(host, opts...)
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("grpc dial node tree service: %w", err) return nil, nil, fmt.Errorf("grpc create node tree service: %w", err)
} }
return conn, grpcService.NewTreeServiceClient(conn), nil return conn, grpcService.NewTreeServiceClient(conn), nil