question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Asp.net core 3.0 Grpc.AspNetCore.Server.ClientFactory Error

See original GitHub issue
Grpc.Core.RpcException: Status(StatusCode=Internal, Detail="Error starting gRPC call: An error occurred while sending the request.")
   at Grpc.Net.Client.Internal.HttpClientCallInvoker.BlockingUnaryCall[TRequest,TResponse](Method`2 method, String host, CallOptions options, TRequest request)
   at Grpc.Core.Interceptors.InterceptingCallInvoker.<BlockingUnaryCall>b__3_0[TRequest,TResponse](TRequest req, ClientInterceptorContext`2 ctx)
   at Grpc.Core.ClientBase.ClientBaseConfiguration.ClientBaseConfigurationInterceptor.BlockingUnaryCall[TRequest,TResponse](TRequest request, ClientInterceptorContext`2 context, BlockingUnaryCallContinuation`2 continuation)
   at Grpc.Core.Interceptors.InterceptingCallInvoker.BlockingUnaryCall[TRequest,TResponse](Method`2 method, String host, CallOptions options, TRequest request)
   at GrpcService2.Chat.ChatClient.SendChat(ChatRequest request, CallOptions options) in C:\Users\Aries\Desktop\ConsoleApp3\ConsoleApp3\obj\Debug\netcoreapp3.0\ChatGrpc.cs:line 92
   at GrpcService2.Chat.ChatClient.SendChat(ChatRequest request, Metadata headers, Nullable`1 deadline, CancellationToken cancellationToken) in C:\Users\Aries\Desktop\ConsoleApp3\ConsoleApp3\obj\Debug\netcoreapp3.0\ChatGrpc.cs:line 88
   at WebApplication1.Controllers.TestController.GetName() in C:\Users\Aries\Desktop\ConsoleApp3\WebApplication1\Controllers\TestController.cs:line 25
   at lambda_method(Closure , Object , Object[] )
   at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

HEADERS

Cache-Control: no-cache Connection: keep-alive Content-Type: application/json Accept: / Accept-Encoding: gzip, deflate Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuaWNrTmFtZSI6IuWPr-i-vum4rSIsImVtYWlsIjoiYWRtaW5AMTYzLmNvbSIsInVpZCI6IjB4MTAyNCIsImFwcENvZGUiOiIyMTQiLCJsb2dpblRpbWUiOiIyMDE5LTEwLTIyIDE2OjU1IiwiZXhwIjoxNTcxNzM4MTM2LCJpc3MiOiJodHRwOi8vMTI3LjAuMC4xIiwiYXVkIjoiemh1cXVlIn0.-W__S8RuM2bvj8t6ZaqwEZQ0nhjX0pc0vE_dXPyosAY Host: localhost:5000 User-Agent: PostmanRuntime/7.19.0 Content-Length: 249 Postman-Token: 605b5837-28b9-42e1-910c-a93a022f7a2a

Code:

   public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddGrpcClient<Chat.ChatClient>(o =>
            {
                o.Address = new Uri("http://192.168.1.109:5001");
            });
        }


 public class TestController : ControllerBase
    {
        private readonly Chat.ChatClient _c;

        public TestController(Chat.ChatClient client)
        {
            _c = client;
        }

        [HttpGet]
        public ActionResult GetName()
        {
            var a = _c.SendChat(new ChatRequest { Name = "test request....." });
            return Ok(a);
        }
    }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

18reactions
Justin-Lessardcommented, Nov 4, 2019

I’ve found a workaround for now.

Setting this flag inside the client seems to make it work.

AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
1reaction
Justin-Lessardcommented, Nov 4, 2019

Not the OP, but I’m able to reproduce. It’s working fine using https but when I try over http, I get the same error.

Exception thrown: ‘Grpc.Core.RpcException’ in System.Private.CoreLib.dll An unhandled exception of type ‘Grpc.Core.RpcException’ occurred in System.Private.CoreLib.dll Status(StatusCode=Internal, Detail=“Error starting gRPC call: An error occurred while sending the request.”)

There is nothing else in the debug logs. I’m able to access the RPC server without any issues using BloomRPC, so I suspect Grpc.Net.Client is at fault.

I’ve looked at the wireshark capture of a failed call using Grpc.Net.Client and here are the results.

No. Time Source Destination Protocol Length Info
1 0 192.168.0.161 172.17.131.244 TCP 66 5186  >  80 [SYN] Seq=0 Win=65535 Len=0 MSS=65495 WS=256 SACK_PERM=1
2 0.000497 172.17.131.244 192.168.0.161 TCP 66 80  >  5186 [SYN, ACK] Seq=0 Ack=1 Win=65535 Len=0 MSS=1460 WS=256 SACK_PERM=1
3 0.00056 192.168.0.161 172.17.131.244 TCP 54 5186  >  80 [ACK] Seq=1 Ack=1 Win=2102272 Len=0
4 0.055721 192.168.0.161 172.17.131.244 TCP 339 5186  >  80 [PSH, ACK] Seq=1 Ack=1 Win=2102272 Len=285 [TCP segment of a reassembled PDU]
5 0.05687 192.168.0.161 172.17.131.244 TCP 59 [TCP segment of a reassembled PDU]
6 0.057291 172.17.131.244 192.168.0.161 TCP 54 80  >  5186 [ACK] Seq=1 Ack=291 Win=2102272 Len=0
7 0.058108 172.17.131.244 192.168.0.161 HTTP2 71 GOAWAY[0]
8 0.058161 192.168.0.161 172.17.131.244 TCP 54 5186  >  80 [ACK] Seq=291 Ack=18 Win=2102272 Len=0
9 0.058282 172.17.131.244 192.168.0.161 TCP 54 80  >  5186 [FIN, ACK] Seq=18 Ack=291 Win=2102272 Len=0
10 0.058314 192.168.0.161 172.17.131.244 TCP 54 5186  >  80 [ACK] Seq=291 Ack=19 Win=2102272 Len=0
11 0.074949 192.168.0.161 172.17.131.244 TCP 54 5186  >  80 [FIN, ACK] Seq=291 Ack=19 Win=2102272 Len=0
12 0.075183 172.17.131.244 192.168.0.161 TCP 54 80  >  5186 [ACK] Seq=19 Ack=292 Win=2102272 Len=0

It’s not really my area of expertise, but it looks like the client never initiate communication using HTTP2 and GRPC after the initial TCP handshake. The client just send the whole message over TCP and is rejected by the server.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot gRPC on .NET
The ASP.NET Core gRPC template and samples use TLS by default. You'll see the following error message when you attempt to start the...
Read more >
Grpc client factory client doesn't wait for service to start
I am using Grpc.Net version : Grpc.AspNetCore 2.27.0. Dot net core version : Asp.Net Core 3.1. Project Sdk for Grpc service ="Microsoft.NET.
Read more >
gRPC with ASP.NET Core 3.0
Abstract: gRPC is supported in the latest ASP.NET Core 3.0 release. This tutorial will cover a brief introduction to gRPC, how gRPC services ......
Read more >
Implementing Microservices with gRPC and .NET Core 3.1
When starting your gRPC service, you may experience an error like the following: Microsoft.AspNetCore.Server.Kestrel[0] Unable to start Kestrel. System.IO.
Read more >
How to build gRPC applications in ASP.NET Core
Learn how to use gRPC, a language-agnostic, high-performance RPC framework, to build lightweight, high-performance services in ASP.NET Core ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found