-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fix HTTP/2 extended connect hang #80066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
...ries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.Http2ExtendedConnect.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.IO; | ||
| using System.Net.Test.Common; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace System.Net.Http.Functional.Tests | ||
| { | ||
| [ConditionalClass(typeof(SocketsHttpHandler), nameof(SocketsHttpHandler.IsSupported))] | ||
| public sealed class SocketsHttpHandler_Http2ExtendedConnect_Test : HttpClientHandlerTestBase | ||
| { | ||
| public SocketsHttpHandler_Http2ExtendedConnect_Test(ITestOutputHelper output) : base(output) { } | ||
|
|
||
| protected override Version UseVersion => HttpVersion.Version20; | ||
|
|
||
| [Theory] | ||
| [InlineData(true)] | ||
| [InlineData(false)] | ||
| public async Task Connect_ReadWriteResponseStream(bool useSsl) | ||
| { | ||
| byte[] clientMessage = new byte[] { 1, 2, 3 }; | ||
| byte[] serverMessage = new byte[] { 4, 5, 6, 7 }; | ||
|
|
||
| TaskCompletionSource clientCompleted = new(TaskCreationOptions.RunContinuationsAsynchronously); | ||
|
|
||
| await Http2LoopbackServerFactory.Singleton.CreateClientAndServerAsync(async uri => | ||
| { | ||
| using HttpClient client = CreateHttpClient(); | ||
|
|
||
| HttpRequestMessage request = CreateRequest(HttpMethod.Connect, uri, UseVersion, exactVersion: true); | ||
| request.Headers.Protocol = "foo"; | ||
|
|
||
| using HttpResponseMessage response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead); | ||
|
|
||
| using Stream responseStream = await response.Content.ReadAsStreamAsync(); | ||
|
|
||
| await responseStream.WriteAsync(clientMessage); | ||
|
|
||
| byte[] readBuffer = new byte[serverMessage.Length]; | ||
| await responseStream.ReadExactlyAsync(readBuffer); | ||
| Assert.Equal(serverMessage, readBuffer); | ||
|
|
||
| // Receive server's EOS | ||
| Assert.Equal(0, await responseStream.ReadAsync(readBuffer)); | ||
|
|
||
| clientCompleted.SetResult(); | ||
| }, | ||
| async server => | ||
| { | ||
| await using Http2LoopbackConnection connection = await ((Http2LoopbackServer)server).EstablishConnectionAsync(new SettingsEntry { SettingId = SettingId.EnableConnect, Value = 1 }); | ||
|
|
||
| (int streamId, _) = await connection.ReadAndParseRequestHeaderAsync(readBody: false); | ||
|
|
||
| await connection.SendResponseHeadersAsync(streamId, endStream: false).ConfigureAwait(false); | ||
|
|
||
| DataFrame dataFrame = await connection.ReadDataFrameAsync(); | ||
| Assert.Equal(clientMessage, dataFrame.Data.ToArray()); | ||
|
|
||
| await connection.SendResponseDataAsync(streamId, serverMessage, endStream: true); | ||
|
|
||
| await clientCompleted.Task.WaitAsync(TestHelper.PassingTestTimeout); | ||
| }, options: new GenericLoopbackOptions { UseSsl = useSsl }); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(true)] | ||
| [InlineData(false)] | ||
| public async Task Connect_ServerDoesNotSupportExtendedConnect_ClientIncludesExceptionData(bool useSsl) | ||
| { | ||
| TaskCompletionSource clientCompleted = new(TaskCreationOptions.RunContinuationsAsynchronously); | ||
|
|
||
| await LoopbackServerFactory.CreateClientAndServerAsync(async uri => | ||
| { | ||
| using HttpClient client = CreateHttpClient(); | ||
|
|
||
| HttpRequestMessage request = CreateRequest(HttpMethod.Connect, uri, UseVersion, exactVersion: true); | ||
| request.Headers.Protocol = "foo"; | ||
|
|
||
| HttpRequestException ex = await Assert.ThrowsAsync<HttpRequestException>(() => client.SendAsync(request)); | ||
|
|
||
| Assert.Equal(false, ex.Data["SETTINGS_ENABLE_CONNECT_PROTOCOL"]); | ||
|
|
||
| clientCompleted.SetResult(); | ||
| }, | ||
| async server => | ||
| { | ||
| try | ||
| { | ||
| await server.AcceptConnectionAsync(async connection => | ||
| { | ||
| await clientCompleted.Task.WaitAsync(TestHelper.PassingTestTimeout); | ||
| }); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _output.WriteLine($"Ignoring exception {ex}"); | ||
| } | ||
| }, options: new GenericLoopbackOptions { UseSsl = useSsl }); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(true)] | ||
| [InlineData(false)] | ||
| public async Task Connect_Http11Endpoint_Throws(bool useSsl) | ||
| { | ||
| using var server = new LoopbackServer(new LoopbackServer.Options | ||
| { | ||
| UseSsl = useSsl | ||
| }); | ||
|
|
||
| await server.ListenAsync(); | ||
|
|
||
| TaskCompletionSource clientCompleted = new(TaskCreationOptions.RunContinuationsAsynchronously); | ||
|
|
||
| Task serverTask = Task.Run(async () => | ||
| { | ||
| try | ||
| { | ||
| await server.AcceptConnectionAsync(async connection => | ||
| { | ||
| if (!useSsl) | ||
| { | ||
| byte[] http2GoAwayHttp11RequiredBytes = new byte[17] { 0, 0, 8, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13 }; | ||
|
|
||
| await connection.SendResponseAsync(http2GoAwayHttp11RequiredBytes); | ||
|
|
||
| await clientCompleted.Task.WaitAsync(TestHelper.PassingTestTimeout); | ||
| } | ||
| }); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _output.WriteLine($"Ignoring exception {ex}"); | ||
| } | ||
| }); | ||
|
|
||
| Task clientTask = Task.Run(async () => | ||
| { | ||
| using HttpClient client = CreateHttpClient(); | ||
|
|
||
| HttpRequestMessage request = CreateRequest(HttpMethod.Connect, server.Address, UseVersion, exactVersion: true); | ||
| request.Headers.Protocol = "foo"; | ||
|
|
||
| Exception ex = await Assert.ThrowsAnyAsync<Exception>(() => client.SendAsync(request)); | ||
| clientCompleted.SetResult(); | ||
|
|
||
| if (useSsl) | ||
| { | ||
| Assert.Equal(false, ex.Data["HTTP2_ENABLED"]); | ||
| } | ||
| }); | ||
|
|
||
| await new[] { serverTask, clientTask }.WhenAllOrAnyFailed().WaitAsync(TestHelper.PassingTestTimeout); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.