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.32k stars 9.97k forks source link

GRPC Server causing Microsoft.AspNetCore.Connections.ConnectionResetException when listening to IPAddress.Any #52952

Open speed2048 opened 9 months ago

speed2048 commented 9 months ago

Is there an existing issue for this?

Describe the bug

When debugging a GRPC server.

I get a Continous exception messages Microsoft.AspNetCore.Connections.ConnectionResetException in System.Private.CoreLib.dll or in System.Net.Security.dll

The code that does this is: options.Listen(IPAddress.Any, portno, ListenOptions => { ListenOptions.UseHttps(); });

If I change it to:

options.Listen(IPAddress.Loopback, portno, ListenOptions => { ListenOptions.UseHttps(); });

No exceptions..

Note; The application does work as intended but concerned of a lot of exceptions that there may be a performance hit.

Expected Behavior

There should not be any exceptions occurring.

Steps To Reproduce

No response

Exceptions (if any)

Continous Microsoft.AspNetCore.Connections.ConnectionResetException when options.Listen is set to IPAddress.Any

.NET Version

8.0.100

Anything else?

.NET SDK: Version: 8.0.100 Commit: 57efcf1350 Workload version: 8.0.100-manifests.3b83835e

Runtime Environment: OS Name: Windows OS Version: 10.0.22631 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.100\

.NET workloads installed: Workload version: 8.0.100-manifests.3b83835e [android] Installation Source: SDK 8.0.100, VS 17.9.34407.89 Manifest Version: 34.0.52/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.android\34.0.52\WorkloadManifest.json Install Type: Msi

[ios] Installation Source: SDK 8.0.100, VS 17.9.34407.89 Manifest Version: 17.0.8490/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.ios\17.0.8490\WorkloadManifest.json Install Type: Msi

[maccatalyst] Installation Source: SDK 8.0.100, VS 17.9.34407.89 Manifest Version: 17.0.8490/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maccatalyst\17.0.8490\WorkloadManifest.json Install Type: Msi

[macos] Installation Source: SDK 8.0.100 Manifest Version: 14.0.8490/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.macos\14.0.8490\WorkloadManifest.json Install Type: Msi

[maui] Installation Source: SDK 8.0.100 Manifest Version: 8.0.3/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maui\8.0.3\WorkloadManifest.json Install Type: Msi

[maui-windows] Installation Source: VS 17.9.34407.89 Manifest Version: 8.0.3/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maui\8.0.3\WorkloadManifest.json Install Type: Msi

Host: Version: 8.0.0 Architecture: x64 Commit: 5535e31a71

.NET SDKs installed: 7.0.404 [C:\Program Files\dotnet\sdk] 8.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found: arm64 [C:\Program Files\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\arm64\InstallLocation] x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables: Not set

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

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

Tratcher commented 9 months ago

What's the message from the exception?

What's in the debug level server logs?

What if you use ListenAnyIP instead?

speed2048 commented 9 months ago

I tried ListenAnyIP and same results. code:

options.ListenAnyIP(portno, ListenOptions => { ListenOptions.UseHttps(); });

Debug level on Server is info or Information.

The console output from the GRPC is not indicating any exceptions , its the Debug output screen from VS2022 that is showing the exceptions. I dont know how to catch those exceptions, any help would be appreciated to capture these exceptions.

speed2048 commented 9 months ago

Was able to get trace logs of some exceptions it was throwing:

dbug: Microsoft.AspNetCore.Hosting.Diagnostics[13] Loaded hosting startup assembly Microsoft.WebTools.BrowserLink.Net info: Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider[1] No action descriptors found. This may indicate an incorrectly configured application or missing application parts. To learn more, visit https://aka.ms/aspnet/mvc/app-parts info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down. info: Microsoft.Hosting.Lifetime[0] Hosting environment: Development info: Microsoft.Hosting.Lifetime[0] Content root path: E:\Projects\BoincSpy.NetCore\BoincSpy.GRPC.Service\BoincSpy.GRPC.Service dbug: Microsoft.Extensions.Hosting.Internal.Host[2] Hosting started dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[39] Connection id "0HN03DRNF19JO" accepted. dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[1] Connection id "0HN03DRNF19JO" started. dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[19] Connection id "0HN03DRNF19JO" reset. dbug: Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware[1] Failed to authenticate HTTPS connection. Microsoft.AspNetCore.Connections.ConnectionResetException: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host. --- 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.DuplexPipeStream.ReadAsyncInternal(Memory1 destination, CancellationToken cancellationToken) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.StateMachineBox1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token) at System.Net.Security.SslStream.EnsureFullTlsFrameAsync[TIOAdapter](CancellationToken cancellationToken, Int32 estimatedSize) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.StateMachineBox1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token) at System.Net.Security.SslStream.ReceiveHandshakeFrameAsync[TIOAdapter](CancellationToken cancellationToken) at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](Boolean receiveFirst, Byte[] reAuthenticationData, CancellationToken cancellationToken) at System.Net.Security.SslStream.ProcessAuthenticationWithTelemetryAsync(Boolean isAsync, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware.OnConnectionAsync(ConnectionContext context) dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[2] Connection id "0HN03DRNF19JO" stopped. dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[7] Connection id "0HN03DRNF19JO" sending FIN because: "The Socket transport's send loop completed gracefully." dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[39] Connection id "0HN03DRNF19JP" accepted. dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[1] Connection id "0HN03DRNF19JP" started. dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[19] Connection id "0HN03DRNF19JP" reset. dbug: Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware[1] Failed to authenticate HTTPS connection. Microsoft.AspNetCore.Connections.ConnectionResetException: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host. --- 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.DuplexPipeStream.ReadAsyncInternal(Memory1 destination, CancellationToken cancellationToken) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.StateMachineBox1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at System.Net.Security.SslStream.EnsureFullTlsFrameAsync[TIOAdapter](CancellationToken cancellationToken, Int32 estimatedSize) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.StateMachineBox1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at System.Net.Security.SslStream.ReceiveHandshakeFrameAsync[TIOAdapter](CancellationToken cancellationToken) at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](Boolean receiveFirst, Byte[] reAuthenticationData, CancellationToken cancellationToken) at System.Net.Security.SslStream.ProcessAuthenticationWithTelemetryAsync(Boolean isAsync, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware.OnConnectionAsync(ConnectionContext context) dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[2] Connection id "0HN03DRNF19JP" stopped. dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[7] Connection id "0HN03DRNF19JP" sending FIN because: "The Socket transport's send loop completed gracefully." dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[39] Connection id "0HN03DRNF19JQ" accepted. dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[1] Connection id "0HN03DRNF19JQ" started. dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[19] Connection id "0HN03DRNF19JQ" reset. dbug: Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware[1] Failed to authenticate HTTPS connection. Microsoft.AspNetCore.Connections.ConnectionResetException: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host. --- 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.DuplexPipeStream.ReadAsyncInternal(Memory1 destination, CancellationToken cancellationToken) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.StateMachineBox1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token) at System.Net.Security.SslStream.EnsureFullTlsFrameAsync[TIOAdapter](CancellationToken cancellationToken, Int32 estimatedSize) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at System.Net.Security.SslStream.ReceiveHandshakeFrameAsync[TIOAdapter](CancellationToken cancellationToken) at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](Boolean receiveFirst, Byte[] reAuthenticationData, CancellationToken cancellationToken) at System.Net.Security.SslStream.ProcessAuthenticationWithTelemetryAsync(Boolean isAsync, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware.OnConnectionAsync(ConnectionContext context) dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[2] Connection id "0HN03DRNF19JQ" stopped. dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[7] Connection id "0HN03DRNF19JQ" sending FIN because: "The Socket transport's send loop completed gracefully." dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[39] Connection id "0HN03DRNF19JR" accepted. dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[1] Connection id "0HN03DRNF19JR" started. dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[19] Connection id "0HN03DRNF19JR" reset. dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[19] Connection id "0HN03DRNF19JR" reset. dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[8] Connection id "0HN03DRNF19JR" sending RST because: "An existing connection was forcibly closed by the remote host." dbug: Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware[3] Connection 0HN03DRNF19JR established using the following protocol: Tls13 dbug: Microsoft.AspNetCore.Server.Kestrel.Http2[48] Connection id "0HN03DRNF19JR" is closed. The last processed stream ID was 0. dbug: Microsoft.AspNetCore.Server.Kestrel.Http2[62] The connection queue processing loop for 0HN03DRNF19JR completed. dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[2] Connection id "0HN03DRNF19JR" stopped. dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[39] Connection id "0HN03DRNF19JS" accepted. dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[1] Connection id "0HN03DRNF19JS" started. dbug: Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware[3] Connection 0HN03DRNF19JS established using the following protocol: Tls13 dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[19] Connection id "0HN03DRNF19JS" reset. dbug: Microsoft.AspNetCore.Server.Kestrel.Http2[48] Connection id "0HN03DRNF19JS" is closed. The last processed stream ID was 0.