Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to make a connection between trivial C# gRPC client and server

Tags:

c#

grpc

I'm trying to get a basic gRPC C# client and server working using the .Net bindings for the official grpc library (version 1.20). But every time my client calls fail to reach the server with this error:

Grpc.Core.RpcException: Status(StatusCode=Unknown, Detail="Stream removed")

The failure is immediate (there is no waiting or timeout) and consistent.

This includes all of the official gRPC examples, all of them build and run out of the box, but fail to call the server with that error. For example:

// Server
Server server = new Server
{
    Services = { Greeter.BindService(new GreeterImpl()) },
    Ports = { new ServerPort("localhost", 50051, ServerCredentials.Insecure) }
};
server.Start();
Console.ReadKey();
server.ShutdownAsync().Wait();

// Client
Channel channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure);
var client = new Greeter.GreeterClient(channel);
var reply = client.SayHello(new HelloRequest { Name = "you" });

I also tried to call the server with the BloomRPC client, with the same error message.

The server service implementation is not called and nothing is written in server logs (with GRPC_TRACE=all and GRPC_VERBOSITY=debug). Here are full client logs with the same settings. Notable excerpt:

D0418 14:53:48.801298 0 ...: set_final_status CLI
D0418 14:53:48.801545 0 ...: {"created":"@1555592028.801000000","description":"Error received from peer","file":"...","file_line":1036,"grpc_message":"Stream removed","grpc_status":2}
I0418 14:53:48.802018 0 ...: ipv4:10.240.240.1:8080: Complete BDP ping err={"created":"@1555592028.790000000","description":"OS Error","file":"T:\src\github\grpc\workspace_csharp_ext_windows_x64\src\core\lib\iomgr\tcp_windows.cc","file_line":344,"os_error":"An established connection was aborted by the software in your host machine.\r\n","syscall":"WSASend","wsa_error":10053}

The server's port appears open in Resource Manager, I am able to invoke the server with telnet and it responds with a few bytes of non-text data (and disconnects as soon as I send any input).

I tried various combinations of host addresses for both client and server ("localhost", "127.0.0.1", "0.0.0.0", my machine's name or IP within the local network), all to the same end.

This is happening on up-to-date Win10, VS 2017, .Net Core 2.1 (happens with 2.0 too). Windows Firewall is disabled. I often develop with other networking technologies (eg. WCF) on this machine and have never faced any such issues.

Interestingly enough, the same exact code works correctly on my home machine out of the box, so it has to be something about the system, but I have been unable to determine what.

EDIT: I experiemented with communication between these C# client and server and an analogous client server in Java (from grpc-java examples).

My observations:

  • Java client CAN call C# server.
  • C# client CAN'T call Java server
  • Java client CAN call Java server
  • C# client CAN'T call C# server.

This produces a simple conclusion: The issue is with the C# client, though I have no explanation why it works on other computers (I have tested it at my colleagues's computer as well and it does work there).

like image 903
Matěj Zábský Avatar asked Apr 18 '19 13:04

Matěj Zábský


2 Answers

Similar to Matěj Zábský I was struggling with "Stream removed" error and failed to get my BloomRPC to call my code. My circumstances were slightly different - my server portion was written with new Grpc.AspNetCore NuGet package in .NET Core 3, where as client was using a Grpc.Core Nuget package (that is compatible with older .NET Frameworks). To get it fixed, on Server side of gRPC I've made this change (I hope this helps someone):

From:

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseStartup<Startup>();
        });

To:

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.ConfigureKestrel(options =>
            {
                // This endpoint will use HTTP/2 and HTTPS on port 5001.
                options.Listen(IPAddress.Any, 5001, listenOptions =>
                {
                    listenOptions.Protocols = HttpProtocols.Http2;
                });
            });

            webBuilder.UseStartup<Startup>();
        });
like image 195
Victor F Avatar answered Oct 23 '22 10:10

Victor F


I have resolved this issue by using the native .Net gRPC library (instead of the ASP.Net Core based one).

like image 1
Matěj Zábský Avatar answered Oct 23 '22 09:10

Matěj Zábský