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.

gRPC has an issue when Kestrel set to Http1AndHttp2 with unsecure urls.

See original GitHub issue

gRPC has an issue when Kestrel set to Http1AndHttp2 with unsecure urls.

This has to do with unsecure URLs. We are using unsecure URLs because we want to host the gRPC services inside Kubernetes cluster with HTTP. We will support HTTPS at the load balancer and offload the TLS. Additionally, we have a development team that has a mix of Windows and Macs and want to support development on the Mac and cannot use HTTPS with gRPC at the moment due to missing ALPN support on the Mac.

Reference: Unable to start AspNet Core gRPC on Mac OS

We are trying to host both gRPC services and would like to host MapGet endpoints. Interestingly, the gRPC template does exactly this. When you use the sample out-of-the-box, it works. But when we change to use an unsecure applicationUrl in launchSettings things stop working.

The MapGet(“/”) fails with an unsecure URL (ex. http://localhost:5000). We are able to get the MapGet(“/”) to work when we change the protocol from Http2 to Http1AndHttp2. Conversely, our gRPC services fails when Kestrel supports both Http1AndHttp2 with an unsecure applicationUrl.

Scenario #1 - Secure URL (https://localhost:5001), Http2 Protocol MapGet Succeeds, gRPC Succeeds

Scenario #2 - Unsecure URL (http://localhost:5000), Http2 Protocol MapGet Fails, gRPC Succeeds

Scenario #3 - Unsecure URL (http://localhost:5000), Http1AndHttp2 Protocol MapGet Succeeds, gRPC Fails

What version of gRPC and what language are you using?

Testing with 2.29.0 and 2.30-pre1

What operating system (Linux, Windows,…) and version?

Windows 10

What runtime / compiler are you using (e.g. .NET Core SDK version dotnet --info)

.NET Core SDK (reflecting any global.json): Version: 3.1.301 Commit: 7feb845744

Runtime Environment: OS Name: Windows OS Version: 10.0.20161 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.301\

Host (useful for support): Version: 3.1.5 Commit: 65cd789777

.NET Core SDKs installed: 2.1.806 [C:\Program Files\dotnet\sdk] 2.2.207 [C:\Program Files\dotnet\sdk] 2.2.402 [C:\Program Files\dotnet\sdk] 3.0.103 [C:\Program Files\dotnet\sdk] 3.1.301 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.0-preview9.19424.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.0-preview3.19555.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0-preview9-19423-09 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.0-preview3.19553.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.0.0-preview9-19423-09 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.0-preview3.19553.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

What did you do?

Start with ASP.NET Core gRPC template. dotnet new grpc -o HelloGrpc

Change launchSettings to unsecure URL breaks MapGet

  "profiles": {
    "DeviceQuery.Host": {
      "commandName": "Project",
      "launchBrowser": true,
      "applicationUrl": "http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}  

Change Kestrel protocols in appsettings.json breaks gRPC “Kestrel”: { “EndpointDefaults”: { “Protocols”: “Http1AndHttp2” } },

What did you expect to see?

MapGet should just work when using an insecure URL and protocol Http2. gRPC should just work when using an insecure URL and protocol Http1AndHttp2

What did you see instead?

We see two failures, one with MapGet and one with gRPC.

Anything else we should know about your project / environment?

We are trying to get this working on Windows first, then on the Mac.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
JamesNKcommented, Jul 11, 2020

This is an expected situation.

Http1AndHttp2 requires TLS for ALPN protocol negotiation. You either need separate ports for HTTP/1.1 and HTTP/2, or use TLS.

See https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-3.1#listenoptionsprotocols

0reactions
qdev89commented, Jan 17, 2022

hi @ChiefInnovator I have exact same issue as you described here. Do you have any workaround for this? It’s really an issue for my end if MapGet can’t work on Unsecure URL and Http2 Protocol. Thanks and regards.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot gRPC on .NET
Insecure gRPC services must be hosted on a HTTP/2-only port. For more information, see ASP.NET Core protocol negotiation. Unable to start ASP.
Read more >
How do I enable http2 in C# Kestrel web server over plain ...
ConfigureKestrel((options) => { // trying to use Http1AndHttp2 causes http2 connections to fail with invalid protocol error // according to ...
Read more >
Using HTTPS with Kestrel in .NET Core
NET app, so I needed a way to use a real, properly signed SSL certificate for a local standalone Kestrel instance. Here's how...
Read more >
Untitled
NET Core GRPC API hosted in a Linux kestrel Azure … Web18 nov. ... 2020 · gRPC has an issue when Kestrel set...
Read more >
Getting Started with ASP.NET Core and gRPC
In this post, we'd like to introduce you to gRPC, one of the newer approaches .NET developers have in designing their APIs.
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