Apache Arrow flight C# implementation code to connect to Dremio

800 views Asked by At

We are trying to connect to dremio service using Apache Arrow Flight C# client. We couldn't find any working code sample in the following links:

https://github.com/dremio-hub/arrow-flight-client-examples

https://github.com/apache/arrow/tree/master/csharp/examples

We tried the following c# code to connect to dremio from arrow flight client which dint worked for us:

String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding(“ISO-8859-1”).GetBytes(“user_name” + “:” + “password”));
var credentials = CallCredentials.FromInterceptor((context, metadata) =>
{
metadata.Add(“Authorization”, "Basic " + encoded);
return Task.CompletedTask;
});
GrpcChannel channel = GrpcChannel.ForAddress(“dremio_url”, new GrpcChannelOptions
{
Credentials = ChannelCredentials.Create(new SslCredentials(), credentials)
});
FlightClient client = new FlightClient(channel);
client.ListActions();
while (await actions.ResponseStream.MoveNext(default))
{
Console.WriteLine(actions.ResponseStream.Current);
}

We are getting the following exception while running the above code:

[2021-10-15T06:14:56.704Z] System.Private.CoreLib: Exception while executing function: ExtractData. Grpc.Net.Client: Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: The SSL connection could not be established, see inner exception. IOException: The handshake failed due to an unexpected packet format.", DebugException="System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. [2021-10-15T06:14:56.721Z] ---> System.IO.IOException: The handshake failed due to an unexpected packet format. [2021-10-15T06:14:56.734Z] at System.Net.Security.SslStream.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) [2021-10-15T06:14:56.772Z] at System.Net.Security.SslStream.PartialFrameCallback(AsyncProtocolRequest asyncRequest)

Any help to resolve the issue in this code sample is greatly appreciated.

1

There are 1 answers

2
Getit On

This appears to be an issue with .NET/grpc using the local cert. Have you tried the following?
This will ignore the cert check. Of course, this is not production code. This is just a workaround for localhost/self-signed cert testing issues:

        // ...
        var handler = new HttpClientHandler();
        // Override this function to workaround local cert issues
        handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true;

        var channel = GrpcChannel.ForAddress(address, new GrpcChannelOptions {
            HttpHandler = handler,
            Credentials = ChannelCredentials.Create(new SslCredentials(), credentials)
        });