-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
WebSockets over HTTP/2 issues #72301
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsDescriptionThe new WebSockets over HTTP/2 feature doesn't work with ASP.NET Core 7. I believe it is because this line runtime/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs Line 1602 in 00d9488
Sepcifically: endStream: (request.Content == null) Causes the END_STREAM flag to be set when sending headers for the CONNECT request.
Additional strange behavior, if you use the Reproduction StepsClient project var webSocket = new ClientWebSocket();
webSocket.Options.HttpVersion = HttpVersion.Version20;
var httpClientHandler = new HttpClientHandler();
await webSocket.ConnectAsync(url, new HttpClient(httpClientHandler), default).ConfigureAwait(false); Server project var builder = WebApplication.CreateBuilder(args);
builder.Logging.SetMinimumLevel(LogLevel.Trace);
builder.WebHost.ConfigureKestrel(o =>
{
o.ConfigureEndpointDefaults(l =>
{
l.UseHttps();
l.UseConnectionLogging();
});
});
var app = builder.Build();
app.UseWebSockets();
app.Run(async context =>
{
var websocket = await context.WebSockets.AcceptWebSocketAsync();
var buf = await websocket.ReceiveAsync(Memory<byte>.Empty, default);
});
app.Run(); Expected behaviorAble to connect to a WebSocket endpoint over HTTP/2. Actual behavior
Regression?No Known WorkaroundsNone ConfigurationNo response Other informationNo response
|
Triage: Incorrect sending of final flag. We should fix it. |
I tested the same scenario with HttpMessageInvoker and it works, it seems that using HttpClient is the root cause as in #72476 @BrennanConroy you mentioned that it failed without handler parameter, could you please provide more details? I cannot reproduce it - connect and send-receive with local server work for me. Is it the same setup, with or without TLS? |
var webSocket = new ClientWebSocket();
webSocket.Options.HttpVersion = HttpVersion.Version20;
await webSocket.ConnectAsync(new Uri("wss://localhost:7204"), default).ConfigureAwait(false);
// this call "succeeds" but the server has closed the websocket connection due to the previous END_STREAM flag
await webSocket.SendAsync(new byte[] { 35, 36, 37 }, WebSocketMessageType.Binary, true, default);
// throws
var res = await webSocket.ReceiveAsync(Array.Empty<byte>(), default); |
Kestrel 7.0.0-rc.1.22368.6 Ah, I see it now. It is strange that switching the order first receive and than send work |
Reopening as the issue does not seem fixed, see #73222 (comment) |
Description
The new WebSockets over HTTP/2 feature doesn't work with ASP.NET Core 7.
I believe it is because this line
runtime/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs
Line 1602 in 00d9488
Sepcifically:
endStream: (request.Content == null)
Causes the END_STREAM flag to be set when sending headers for the CONNECT request.
cc @greenEkatherine
Additional strange behavior, if you use the
ClientWebSocket
without passing in anHttpClientHandler
then theConnectAsync
call does not throw, but the websocket is closed on the server side.Reproduction Steps
Client project
Server project
Expected behavior
Able to connect to a WebSocket endpoint over HTTP/2.
Actual behavior
Regression?
No
Known Workarounds
None
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: