diff --git a/pkg/services/object/search/v2/request_forwarder.go b/pkg/services/object/search/v2/request_forwarder.go index 7bb6e4d3c..1362b03a8 100644 --- a/pkg/services/object/search/v2/request_forwarder.go +++ b/pkg/services/object/search/v2/request_forwarder.go @@ -17,6 +17,10 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/session" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/signature" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + healthV1 "google.golang.org/grpc/health/grpc_health_v1" + "google.golang.org/grpc/status" ) type requestForwarder struct { @@ -25,6 +29,21 @@ type requestForwarder struct { Key *ecdsa.PrivateKey } +func rpcSearchDialer(ctx context.Context, cc grpc.ClientConnInterface) error { + healthClient := healthV1.NewHealthClient(cc) + resp, err := healthClient.Check(ctx, &healthV1.HealthCheckRequest{}) + if err != nil { + if status.Code(err) == codes.Unimplemented { + return nil + } + return fmt.Errorf("health check error: %w", err) + } + if resp.GetStatus() != healthV1.HealthCheckResponse_SERVING { + return errors.New("unavailable grpc server") + } + return nil +} + func (f *requestForwarder) forwardRequest(ctx context.Context, addr network.Address, c client.MultiAddressClient, pubkey []byte) ([]oid.ID, error) { var err error @@ -47,7 +66,7 @@ func (f *requestForwarder) forwardRequest(ctx context.Context, addr network.Addr var searchStream *rpc.SearchResponseReader err = c.RawForAddress(ctx, addr, func(cli *rpcclient.Client) error { - searchStream, err = rpc.SearchObjects(cli, f.Request, rpcclient.WithContext(ctx)) + searchStream, err = rpc.SearchObjects(cli, f.Request, rpcclient.WithContext(ctx), rpcclient.WithDialer(rpcSearchDialer)) return err }) if err != nil {