dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.38k stars 10k forks source link

[dotnet-sdk-7.0.100-preview.6.22313.7] Blazor Server apps with System.Net.WebSockets.WebSocketException Error when accessing with https #42224

Closed Junjun-zhao closed 2 years ago

Junjun-zhao commented 2 years ago

Is there an existing issue for this?

Describe the bug

*When binding the https for "Kestrel" via appsettings.json, --urls or set the ASPNETCORE_URLS environment variable, Blazor server app site can be launched with https://:5001, but it will be disconnected about every 5s.**

Application Name : eShopOnBlazor, OqtaneFramework, EasyDataBasicDemoBlazorAppServerNet5, Blazorise,BlazorPolyfill(Blazor Server apps running on .net7 preview 6) OS: Windows 10 RS5 CPU: X64 .NET Build Number: dotnet-sdk-7.0.100-preview.6.22313.7 Also can check details from Devdiv Bug: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1555938

Expected Behavior

App will launch successful.

Steps To Reproduce

The machine has dotnet-sdk-7.0.100-preview.6.22313.7 installed

1) Create blazor server app: dotnet new blazorserver 2) Add this line to appsettings.json for workaround : (https://github.com/dotnet/aspnetcore/issues/42161)

{
  "Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://localhost:5000"
      },
      "Https": {
        "Url": "https://localhost:5001"
      }
    }
  }
}

3) Publish the app 4) Run the app 5) Go to https://localhost:5001

Exceptions (if any)

App will launch but it will disconnect every 5 seconds

Exception:

dbug: Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher[1]
      Received hub invocation: InvocationMessage { InvocationId: "0", Target: "ConnectCircuit", Arguments: [ CfDJ8AYSpQtcIQlEtmnE9v80hhPUStHYmXqWNAynR434yWDQx4lxFI0bjNOgGYkSJ-0lsvSk7UuVPgKlJOWhIL4v_4ssVv69Eir-dHoC8Fckb12Y2SP68Pq5n-z4n77zPzGflvnoD27odwNiHKkFv6MLcuuoC9VOav_bGDF-I_6l8lkFF-dixudaVyKS7tnTLh3-tKZil7zpOEW4NGem_hwOGLw ], StreamIds: [  ] }.
dbug: Microsoft.AspNetCore.Http.Connections.Internal.Transports.WebSocketsTransport[14]
      Socket connection closed prematurely.
      System.Net.WebSockets.WebSocketException (0x80004005): The remote party closed the WebSocket connection without completing the close handshake.
       ---> System.IO.IOException: The request stream was aborted.
       ---> Microsoft.AspNetCore.Connections.ConnectionAbortedException: The HTTP/2 connection faulted.
         --- End of inner exception stack trace ---
         at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result)
         at System.IO.Pipelines.Pipe.GetReadAsyncResult()
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2MessageBody.ReadAsync(CancellationToken cancellationToken)
         at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.ReadAsyncInternal(Memory`1 destination, CancellationToken cancellationToken)
         at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
         at System.IO.Stream.ReadAtLeastAsyncCore(Memory`1 buffer, Int32 minimumBytes, Boolean throwOnEndOfStream, CancellationToken cancellationToken)
         at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
         at System.Net.WebSockets.ManagedWebSocket.EnsureBufferContainsAsync(Int32 minimumRequiredBytes, CancellationToken cancellationToken)
         at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
         at System.Net.WebSockets.ManagedWebSocket.ReceiveAsyncPrivate[TResult](Memory`1 payloadBuffer, CancellationToken cancellationToken)
         at System.Net.WebSockets.ManagedWebSocket.ReceiveAsyncPrivate[TResult](Memory`1 payloadBuffer, CancellationToken cancellationToken)
         at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
         at Microsoft.AspNetCore.Http.Connections.Internal.Transports.WebSocketsServerTransport.StartReceiving(WebSocket socket)
dbug: Microsoft.AspNetCore.Http.Connections.Internal.Transports.WebSocketsTransport[4]
      Waiting for the application to finish sending data.

.NET Version

dotnet-sdk-7.0.100-preview.6.22313.7

Anything else?

C:\Users\v-gwei>dotnet --info
.NET SDK:
 Version:   7.0.100-preview.6.22313.7
 Commit:    693b8eb2cc

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19044
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\7.0.100-preview.6.22313.7\

global.json file:
  Not found

Host:
  Version:      7.0.0-preview.6.22312.1
  Architecture: x64
  Commit:       5c5e66e6c0

.NET SDKs installed:
  7.0.100-preview.6.22313.7 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 7.0.0-preview.6.22312.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 7.0.0-preview.6.22312.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 7.0.0-preview.6.22311.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Download .NET:
https://aka.ms/dotnet-download

Learn about .NET Runtimes and SDKs:
https://aka.ms/dotnet/runtimes-sdk-info

@dotnet-actwx-bot @dotnet/compat

davidfowl commented 2 years ago

cc @DamianEdwards

Tratcher commented 2 years ago

This might be caused by https://github.com/dotnet/aspnetcore/issues/42101 and the new H2 WebSockets support.

Tratcher commented 2 years ago

Confirmed, I see the browser disconnecting and retrying every ~6s, and I see the below logs:

dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[7]
      Connection id "0HMIFMSBPIM66" sending FIN because: "Reading the request body timed out due to data arriving too slowly. See MinRequestBodyDataRate."
dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[19]
      Connection id "0HMIFMSBPIM66" reset.
dbug: Microsoft.AspNetCore.Http.Connections.Internal.Transports.WebSocketsTransport[14]
      Socket connection closed prematurely.
      System.Net.WebSockets.WebSocketException (0x80004005): The remote party closed the WebSocket connection without completing the close handshake.
       ---> System.IO.IOException: The request stream was aborted.
       ---> Microsoft.AspNetCore.Connections.ConnectionAbortedException: The HTTP/2 connection faulted.
         --- End of inner exception stack trace ---
         at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result)
         at System.IO.Pipelines.Pipe.GetReadAsyncResult()
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2MessageBody.ReadAsync(CancellationToken cancellationToken) in D:\github\aspnetcore\src\Servers\Kestrel\Core\src\Internal\Http2\Http2MessageBody.cs:line 98
         at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.ReadAsyncInternal(Memory`1 destination, CancellationToken cancellationToken) in D:\github\aspnetcore\src\Servers\Kestrel\Core\src\Internal\Http\HttpRequestStream.cs:line 118
         at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
         at System.IO.Stream.ReadAtLeastAsyncCore(Memory`1 buffer, Int32 minimumBytes, Boolean throwOnEndOfStream, CancellationToken cancellationToken)
         at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
         at System.Net.WebSockets.ManagedWebSocket.EnsureBufferContainsAsync(Int32 minimumRequiredBytes, CancellationToken cancellationToken)
         at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
         at System.Net.WebSockets.ManagedWebSocket.ReceiveAsyncPrivate[TResult](Memory`1 payloadBuffer, CancellationToken cancellationToken)
         at System.Net.WebSockets.ManagedWebSocket.ReceiveAsyncPrivate[TResult](Memory`1 payloadBuffer, CancellationToken cancellationToken)
         at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
         at Microsoft.AspNetCore.Http.Connections.Internal.Transports.WebSocketsServerTransport.StartReceiving(WebSocket socket) in D:\github\aspnetcore\src\SignalR

Workaround:

                webBuilder.ConfigureKestrel(o =>
                {
                    o.Limits.MinRequestBodyDataRate = null;
                });
Junjun-zhao commented 2 years ago

Thanks @Tratcher. The issue is not added with Label "Bug". Will this issue be fixed in .NET 7 or will provide the workaround to users? It affects all the blazor server apps using https.

davidfowl commented 2 years ago

If this ends up being used by default for signalr and blazor server then we'll need to fix this in preview6.

Tratcher commented 2 years ago

Yes this is a bug that needs to be fixed. https://github.com/dotnet/aspnetcore/issues/42101 will address this.

Junjun-zhao commented 2 years ago

Verified and Fixed on dotnet-sdk-7.0.100-preview.7.22324.4