Skip to content
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

rework SocketsHttpHandler request queue handling for HTTP/1.1 and HTTP/2 #53851

Merged
merged 9 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,20 @@ public async ValueTask<T> WaitWithCancellationAsync(CancellationToken cancellati
return await Task.ConfigureAwait(false);
}
}

public T WaitWithCancellation(CancellationToken cancellationToken)
{
using (cancellationToken.UnsafeRegister(static (s, cancellationToken) => ((TaskCompletionSourceWithCancellation<T>)s!).TrySetCanceled(cancellationToken), this))
{
return Task.GetAwaiter().GetResult();
}
}

public ValueTask<T> WaitWithCancellationAsync(bool async, CancellationToken cancellationToken)
{
return async ?
WaitWithCancellationAsync(cancellationToken) :
new ValueTask<T>(WaitWithCancellation(cancellationToken));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
lock (Console.Out)
{
string text = $"[{eventData.EventSource.Name}-{eventData.EventId}]{(eventData.Payload != null ? $" ({string.Join(", ", eventData.Payload)})." : "")}";
string text = $"[{eventData.EventSource.Name}-{eventData.EventName}]{(eventData.Payload != null ? $" ({string.Join(", ", eventData.Payload)})." : "")}";
if (_eventFilter != null && text.Contains(_eventFilter))
{
ConsoleColor origForeground = Console.ForegroundColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async url =>
using (HttpClient client = CreateHttpClient(handler))
{
client.DefaultRequestHeaders.ConnectionClose = true; // to avoid issues with connection pooling
await client.GetAsync(url1);
await client.GetAsync(url1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT:

Suggested change
await client.GetAsync(url1);
await client.GetAsync(url1);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what happened here :)

}
},
async server =>
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/System.Net.Http/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,9 @@
<data name="net_http_request_timedout" xml:space="preserve">
<value>The request was canceled due to the configured HttpClient.Timeout of {0} seconds elapsing.</value>
</data>
<data name="net_http_connect_timedout" xml:space="preserve">
<value>A connection could not be established within the configured ConnectTimeout.</value>
</data>
<data name="net_quic_connectionaborted" xml:space="preserve">
<value>Connection aborted by peer ({0}).</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ private static async Task<HttpResponseMessage> SendWithNtAuthAsync(HttpRequestMe
if (response.Headers.ConnectionClose.GetValueOrDefault())
{
// Server is closing the connection and asking us to authenticate on a new connection.

// First, detach the current connection from the pool. This means it will no longer count against the connection limit.
// Instead, it will be replaced by the new connection below.
connection.DetachFromPool();

connection = await connectionPool.CreateHttp11ConnectionAsync(request, async, cancellationToken).ConfigureAwait(false);
connectionPool.IncrementConnectionCount();
connection!.Acquire();
isNewConnection = true;
needDrain = false;
Expand Down
Loading