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.

HTTP/2 connection error (PROTOCOL_ERROR): Invalid HTTP/2 connection preface

See original GitHub issue

Change the server configuration of the sample to Kestrel, and then connect aspnetcore grpc-web through Http protocol , The following error occurred:

dbug: Microsoft.AspNetCore.Server.Kestrel[29]
      Connection id "0HLTV45E8MTR4": 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(ReadOnlySequence`1& buffer, SequencePosition& consumed, SequencePosition& examined)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2Connection.TryReadPrefaceAsync()
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2Connection.ProcessRequestsAsync[TContext](IHttpApplication`1 application)

But using iisexpress to start the service, and the client connects through the http protocol, it works fine

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
JamesNKcommented, Mar 9, 2020

This is failing because you are trying to call a HTTP/2 only port without TLS (HTTPS). That isn’t supported by browsers. You either need to use TLS, or change protocols to Microsoft.AspNetCore.Server.Kestrel.Core.HttpProtocols.Http1AndHttp2 (although it will always use HTTP/1.1 because TLS is not available)

1reaction
dingsongjiecommented, Mar 5, 2020

Can you provide your appSettings.json and any modifications you made to the sample to change it to Kestrel? This is a scenario we generally expect to work (and has in the past) so having the full context will help identify what might be different now.

I removed all Kestrel related configuration in appsetting, and this is my Program.cs

               .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                    webBuilder.UseKestrel(option =>
                    {
                        option.ListenAnyIP(82, config =>
                        {
                            config.Protocols = Microsoft.AspNetCore.Server.Kestrel.Core.HttpProtocols.Http2;
                            //config.UseHttps();
                        });
                    });
                });

If you start debugging in visual studio in console , do not use IIS EXPRESS , then use javascript grpc-web client to connect it through the http protocol , you will see this error if you set “Microsoft.AspNetCore.Server.Kestrel”: “Debug”

When you set config.UseHttps() , the javascript client will connect success through the https protocol

Read more comments on GitHub >

github_iconTop Results From Across the Web

Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2. ...
Http2.Http2ConnectionErrorException: HTTP/2 connection error (PROTOCOL_ERROR): Invalid HTTP/2 connection preface. I will describe my conditions.
Read more >
RFC 7540 - Hypertext Transfer Protocol Version 2 (HTTP/2)
Clients and servers MUST treat an invalid connection preface as a connection error (Section 5.4.1) of type PROTOCOL_ERROR. A GOAWAY frame (Section 6.8)...
Read more >
Re: Invalid HTTP2 preface handling?
I'm wondering what would be the problem if on an invalid preface, the > server check if it is actually a valid HTTP/1...
Read more >
Getting 'Invalid HTTP/2 preamble' when 'DISABLE_SSL: true'
I have my jetconf server working fine with 'DISABLE_SSL: false' When I try to use jetconf with http instead of https, it fails...
Read more >
gRPC – What I Broke
Internal.Http2.Http2ConnectionErrorException: HTTP/2 connection error (PROTOCOL_ERROR): Invalid HTTP/2 connection preface. at Microsoft.AspNetCore.Server.
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