Repository navigation
Closed
dotnet/corefx
#37050Labels
enhancementProduct code improvement that does NOT require public API changes/additions
Milestone
Description
- Server that only supports HTTP1
- Enable HTTP/2:
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); - Create HttpRequestMessage with Version = 2.0
- Call server
HttpClient.SendAsync throws this exception the first call:
System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'SslStream'.
at System.Net.Security.SslStream.ThrowIfExceptional()
at System.Net.Security.SslStream.CheckThrow(Boolean authSuccessCheck, Boolean shutdownCheck)
at System.Net.Security.SslStream.WriteAsync(ReadOnlyMemory`1 buffer, CancellationToken cancellationToken)
at System.Net.Http.Http2Connection.FlushOutgoingBytesAsync()
at System.Net.Http.Http2Connection.SendHeadersAsync(HttpRequestMessage request)
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Net.Http.Http2Connection.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.Http2Connection.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.DiagnosticsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
at BenchmarkClient.Program.<>c__DisplayClass5_1.<<Main>b__1>d.MoveNext() in C:\Development\Source\grpc-dotnet\perf\benchmarkapps\BenchmarkClient\Program.cs:line 179
Repeating the call with the HttpClient throws a different exception:
System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'CreditManager'.
at System.Net.Http.CreditManager.RequestCreditAsync(Int32 amount)
at System.Net.Http.Http2Connection.SendHeadersAsync(HttpRequestMessage request)
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Net.Http.Http2Connection.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.Http2Connection.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.DiagnosticsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
at BenchmarkClient.Program.<>c__DisplayClass5_1.<<Main>b__1>d.MoveNext() in C:\Development\Source\grpc-dotnet\perf\benchmarkapps\BenchmarkClient\Program.cs:line 179
I would expect a friendly error message that the server does not support HTTP/2.
.NET Core SDK (reflecting any global.json):
Version: 3.0.100-preview4-011108
Commit: 7cc4cca27b
Metadata
Metadata
Assignees
Labels
enhancementProduct code improvement that does NOT require public API changes/additions
Activity
[-]Odd exceptions with HttpClient and HTTP/2[/-][+]Unhelpful exceptions with HttpClient and HTTP/2[/+]stephentoub commentedon Apr 8, 2019
The server supports HTTP/1.1 with SSL? If so, I wouldn't expect an error here at all, rather simply downgrading to 1.1.
Do you have a repro you can share? What server?
JamesNK commentedon Apr 8, 2019
Server is Kestrel.
https://github.com/JamesNK/grpc-dotnet/tree/jamesnk/httpclient-error-repo
wfurt commentedon Apr 8, 2019
Do you have packet capture? I would be interested to se ALPN negotiation. As @stephentoub mentioned, we should downgrade to HTTP/1.1 if H/2 is not negotiated.
JamesNK commentedon Apr 8, 2019
Wireshark - http2-http1-error.zip
If you want the packets unencrypted then you'll need to run the app yourself. I couldn't get Wireshark to do it.
wfurt commentedon Apr 8, 2019
The server negotiated H/2 from the list so it is expected that it can talk HTTP/2. That does not mean the current exception is useful. It is also little bit strange that the exception is not consistent.
[-]Unhelpful exceptions with HttpClient and HTTP/2[/-][+]HTTP2: Unhelpful exceptions with HttpClient and HTTP/2 when not supported by server[/+]