Aspnetcore.docs: GrPC invalid http/2 connection preface

Created on 4 Jul 2019  Â·  14Comments  Â·  Source: dotnet/AspNetCore.Docs

Microsoft.AspNetCore.Server.Kestrel: Information: Connection id "0HLO001722806": HTTP/2 connection error.

Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2ConnectionErrorException: HTTP/2 connection error (PROTOCOL_ERROR): Invalid HTTP/2 connection preface.
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2Connection.ParsePreface(ReadOnlySequence1& buffer, SequencePosition& consumed, SequencePosition& examined) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2Connection.TryReadPrefaceAsync() at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2Connection.ProcessRequestsAsyncTContext
Microsoft.AspNetCore.Server.Kestrel: Information: Connection id "0HLO001722807": HTTP/2 connection error.

Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2ConnectionErrorException: HTTP/2 connection error (PROTOCOL_ERROR): Invalid HTTP/2 connection preface.
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2Connection.ParsePreface(ReadOnlySequence1& buffer, SequencePosition& consumed, SequencePosition& examined) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2Connection.TryReadPrefaceAsync() at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2Connection.ProcessRequestsAsyncTContext
Microsoft.AspNetCore.Server.Kestrel: Information: Connection id "0HLO001722808": HTTP/2 connection error.

Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2ConnectionErrorException: HTTP/2 connection error (PROTOCOL_ERROR): Invalid HTTP/2 connection preface.
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2Connection.ParsePreface(ReadOnlySequence1& buffer, SequencePosition& consumed, SequencePosition& examined) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2Connection.TryReadPrefaceAsync() at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2Connection.ProcessRequestsAsyncTContext
Microsoft.Hosting.Lifetime: Information: Application is shutting down...
EventSource Error: ERROR: Exception during construction of EventSource Microsoft-System-Net-Primitives: Incorrect function.
The program '[15348] GrPC.exe: Program Trace' has exited with code 0 (0x0).
The program '[15348] GrPC.exe' has exited with code -1073741510 (0xc000013a).


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

PU Source - Docs.ms

Most helpful comment

Hi everyone

I think the issue here is a mis-match between the server and the client over whether to use HTTPS.

Grpc.Net.Client by default will use HTTPS:

    var httpClient = new HttpClient();
    // The port number(5001) must match the port of the gRPC server.
    httpClient.BaseAddress = new Uri("https://localhost:5001");
    var client = GrpcClient.Create<Greeter.GreeterClient>(httpClient);

To use Grpc.Net.Client without TLS you must set an app context switch and change the base address to start with http:

    AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
    var httpClient = new HttpClient();
    // The port number(5001) must match the port of the gRPC server.
    httpClient.BaseAddress = new Uri("http://localhost:5001");
    var client = GrpcClient.Create<Greeter.GreeterClient>(httpClient);

All 14 comments

dotnet --version ?

it is 3.0
3.0.100-preview6-012264
<PropertyGroup> <TargetFramework>netcoreapp3.0</TargetFramework> </PropertyGroup>

I bumped into the same issue with the Greeter sample and the fallback was to bypass Grpc.Net.Client and use just Grpc.Core.
Hope this helps!

I am facing the exact same situation

I bumped into the same issue with the Greeter sample and the fallback was to bypass Grpc.Net.Client and use just Grpc.Core.
Hope this helps!

Thanks a lot, I solved the problem in this way.

I bumped into the same issue with the Greeter sample and the fallback was to bypass Grpc.Net.Client and use just Grpc.Core.
Hope this helps!

It helped. Thanks.

This is an issue with preview7 as well. Any plan to fix this in final release?

I bumped into the same issue with the Greeter sample and the fallback was to bypass Grpc.Net.Client and use just Grpc.Core.
Hope this helps!

Thank you! This solved my problem

I bumped into the same issue with the Greeter sample and the fallback was to bypass Grpc.Net.Client and use just Grpc.Core.
Hope this helps!

@iulianaciura could you add more context for how you used core to get around this? Maybe a example? Thanks.

Hi everyone

I think the issue here is a mis-match between the server and the client over whether to use HTTPS.

Grpc.Net.Client by default will use HTTPS:

    var httpClient = new HttpClient();
    // The port number(5001) must match the port of the gRPC server.
    httpClient.BaseAddress = new Uri("https://localhost:5001");
    var client = GrpcClient.Create<Greeter.GreeterClient>(httpClient);

To use Grpc.Net.Client without TLS you must set an app context switch and change the base address to start with http:

    AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
    var httpClient = new HttpClient();
    // The port number(5001) must match the port of the gRPC server.
    httpClient.BaseAddress = new Uri("http://localhost:5001");
    var client = GrpcClient.Create<Greeter.GreeterClient>(httpClient);

When you run the gRPC server, what is the console output when it starts?

For example:

C:\Development\Source\AspNetCore.Docs\aspnetcore\tutorials\grpc\grpc-start\sample\GrpcGreeter [jamesnk/grpc-sample-fix ≡]> dotnet run
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\Development\Source\AspNetCore.Docs\aspnetcore\tutorials\grpc\grpc-start\sample\GrpcGreeter

Now listening on: https://localhost:5001 indicates that you want to use HTTPS to call the server.

Hi everyone

I think the issue here is a mis-match between the server and the client over whether to use HTTPS.

Grpc.Net.Client by default will use HTTPS:

    var httpClient = new HttpClient();
    // The port number(5001) must match the port of the gRPC server.
    httpClient.BaseAddress = new Uri("https://localhost:5001");
    var client = GrpcClient.Create<Greeter.GreeterClient>(httpClient);

To use Grpc.Net.Client without TLS you must set an app context switch and change the base address to start with http:

    AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
    var httpClient = new HttpClient();
    // The port number(5001) must match the port of the gRPC server.
    httpClient.BaseAddress = new Uri("http://localhost:5001");
    var client = GrpcClient.Create<Greeter.GreeterClient>(httpClient);

This worked great for me @JamesNK thank you. Is this expected to be a flag later on or are we expected to be adjusting the context in the future if we require http?

Thanks.

I don't know of plans to make HTTP/2 without TLS officially supported.

Disclaimer that you should only use HTTP in development. Always use HTTPS for real data over the internet.

As no browser supports HTTP/2 without TLS encryption is defacto mandatory. You're in uncharted and unsupported scenarios. This will not be exposed as a flag, and will remain only available as an AppContext switch which we will remove at some point.

Documentation on common TLS errors has been added here - https://docs.microsoft.com/en-us/aspnet/core/grpc/troubleshoot?view=aspnetcore-3.0

Was this page helpful?
0 / 5 - 0 ratings