0

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.

Gandhi
  • 11,875
  • 4
  • 39
  • 63
  • @outis updated the question – Gandhi Oct 15 '21 at 06:38
  • Have you checked the server connection? Specifically, that it properly supports HTTPS, and you can connect to it with other clients (pre-built, rather than your code)? Or are you literally trying to connect to "dremio_url"? – outis Oct 15 '21 at 07:01
  • @outis ya we did tried and it works. The dremio service infact is enabled for both http and https connectivity. We are able to connect to this service using java client. – Gandhi Oct 15 '21 at 07:15

1 Answers1

0

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)
        });
Getit
  • 1
  • 2
  • Tried but dint work... – Gandhi Feb 23 '23 at 05:42
  • Same error or new error? The other workaround to the cert error was to add cert to my local keychain (using Mac). `sudo security add-trusted-cert -d -r trustRoot -k "/Library/Keychains/System.keychain" localhost.crt` – Getit Mar 02 '23 at 00:56