Aspnetcore: ASP.NET Core 2.1 RC1: SocketException: An existing connection was forcibly closed by the remote host

Created on 9 May 2018  路  9Comments  路  Source: dotnet/aspnetcore

After upgrading my application to ASP.NET Core 2.1 RC1 it suddenly throws a SocketException and exits when debugging it in Visual Studio using the command line launch profile.

The following exception is thrown:

System.AggregateException
  HResult=0x80131500
  Message=One or more errors occurred.
  Source=System.IO.Pipelines
  StackTrace:
   at System.IO.Pipelines.PipeCompletionCallbacks.Execute()
   at System.IO.Pipelines.Pipe.<>c.<.cctor>b__79_2(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()

Inner Exception 1:
SocketException: An existing connection was forcibly closed by the remote host

Environment

位 dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.1.300-rc1-008673
 Commit:    f5e3ddbe73

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.16299
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.300-rc1-008673\

Host (useful for support):
  Version: 2.1.0-rc1
  Commit:  eb9bc92051

.NET Core SDKs installed:
  2.1.104 [C:\Program Files\dotnet\sdk]
  2.1.200 [C:\Program Files\dotnet\sdk]
  2.1.300-preview2-008533 [C:\Program Files\dotnet\sdk]
  2.1.300-rc1-008673 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.0-preview1-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.0-preview2-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.0-rc1-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.0-preview1-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.0-preview2-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.0-rc1-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.0-preview1-26216-03 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.0-preview2-26406-04 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.0-rc1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

Steps to reproduce

  1. Create a new, empty Web Application targeting ASP.NET Core 2.1 RC1 and check "Configure HTTPS"
  2. Start debugging. make a few requests to application and wait a while

This bug does not seem to reproduce when removing the HTTPS endpoint or moving it to the second endpoint and only calling the HTTP endpoint like this:

"applicationUrl": "http://localhost:5000;https://localhost:5001"

Most helpful comment

All 9 comments

@halter73

Just updated to 2.1 RC and I get the same error. the way I can recreate this is by refreshing the page quickly.
System.AggregateException
HResult=0x80131500
Message=One or more errors occurred.
Source=System.IO.Pipelines
StackTrace:
at System.IO.Pipelines.PipeCompletionCallbacks.Execute()
at System.IO.Pipelines.Pipe.<>c.<.cctor>b__79_2(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Threading.ThreadPoolWorkQueue.Dispatch()

Inner Exception 1:
SocketException: An existing connection was forcibly closed by the remote host

System.AggregateException
HResult=0x80131500
Message=One or more errors occurred.
Source=System.IO.Pipelines
StackTrace:
at System.IO.Pipelines.PipeCompletionCallbacks.Execute()
at System.IO.Pipelines.Pipe.<>c.<.cctor>b__79_2(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Threading.ThreadPoolWorkQueue.Dispatch()

Inner Exception 1:
SocketException: An existing connection was forcibly closed by the remote host

Experiencing the same problem here: ASP Core 2.1 RC

dbug: HttpsConnectionAdapter[1]
Failed to authenticate HTTPS connection.
System.IO.IOException: Authentication failed because the remote party has closed the transport stream.
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.Security.SslStream.BeginAuthenticateAsServer(SslServerAuthenticationOptions sslServerAuthenticationOptions, CancellationToken cancellationToken, AsyncCallback asyncCallback, Object asyncState)
at System.Net.Security.SslStream.<>c.b__51_0(SslServerAuthenticationOptions arg1, CancellationToken arg2, AsyncCallback callback, Object state)
at System.Threading.Tasks.TaskFactory1.FromAsyncImpl[TArg1,TArg2](Func5 beginMethod, Func2 endFunction, Action1 endAction, TArg1 arg1, TArg2 arg2, Object state, TaskCreationOptions creationOptions)
at System.Threading.Tasks.TaskFactory.FromAsyncTArg1,TArg2
at System.Threading.Tasks.TaskFactory.FromAsyncTArg1,TArg2
at System.Net.Security.SslStream.AuthenticateAsServerAsync(SslServerAuthenticationOptions sslServerAuthenticationOptions, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionAdapter.InnerOnConnectionAsync(ConnectionAdapterContext context)
dbug: HttpsConnectionAdapter[1]
Failed to authenticate HTTPS connection.
System.IO.IOException: Authentication failed because the remote party has closed the transport stream.
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.Security.SslStream.BeginAuthenticateAsServer(SslServerAuthenticationOptions sslServerAuthenticationOptions, CancellationToken cancellationToken, AsyncCallback asyncCallback, Object asyncState)
at System.Net.Security.SslStream.<>c.b__51_0(SslServerAuthenticationOptions arg1, CancellationToken arg2, AsyncCallback callback, Object state)
at System.Threading.Tasks.TaskFactory1.FromAsyncImpl[TArg1,TArg2](Func5 beginMethod, Func2 endFunction, Action1 endAction, TArg1 arg1, TArg2 arg2, Object state, TaskCreationOptions creationOptions)
at System.Threading.Tasks.TaskFactory.FromAsyncTArg1,TArg2
at System.Threading.Tasks.TaskFactory.FromAsyncTArg1,TArg2
at System.Net.Security.SslStream.AuthenticateAsServerAsync(SslServerAuthenticationOptions sslServerAuthenticationOptions, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionAdapter.InnerOnConnectionAsync(ConnectionAdapterContext context)

Why is that the same problem? The call stack is completely different

I'm not sure if that part of the call stack is related to this error or not.
but VS goes to Application break mode showing me the unhandled exception "SocketException: An existing connection was forcibly closed by the remote host" whenever I submit on Register or Login form(on the Default template)

@halter73 should this issue be resolved with https://github.com/aspnet/KestrelHttpServer/pull/2562?

@henkmollema It appears that way. The "inner exception stack trace" seen in aspnet/KestrelHttpServer#2554 is cut off in this report, so it's hard to be 100% sure that the exception originated from Socket.Shutdown, but it sure seems like it.

@halter73 not sure why it didn't add the inner exception to the stack trace. However, it seems that the exception was indeed thrown by Socket.Shutdown:

System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
   at System.Net.Sockets.Socket.Shutdown(SocketShutdown how)
   at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketConnection.Shutdown()
   at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketConnection.Abort()
   at Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.TransportConnection.Microsoft.AspNetCore.Connections.Features.IConnectionLifetimeFeature.Abort()
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1OutputProducer.Abort(Exception error)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.Abort(Exception error)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.HttpConnection.Abort(Exception ex)
   at System.IO.Pipelines.PipeCompletionCallbacks.Execute()

So I guess this is fixed then. I'll close this issue, thanks! 馃槃

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FourLeafClover picture FourLeafClover  路  3Comments

ipinak picture ipinak  路  3Comments

snebjorn picture snebjorn  路  3Comments

Kevenvz picture Kevenvz  路  3Comments

ermithun picture ermithun  路  3Comments