Handle SocketError.ProtocolType as a connection reset on macOS (#2845)

* Handle SocketError.ProtocolType as a connection reset on macOS
* Make IsConnectionResetError and IsConnectionAbortError stricter
This commit is contained in:
Stephen Halter 2018-08-23 19:16:44 -07:00 committed by GitHub
parent e5a1101239
commit fc3c2eef5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -327,9 +327,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal
private static bool IsConnectionResetError(SocketError errorCode) private static bool IsConnectionResetError(SocketError errorCode)
{ {
// A connection reset can be reported as SocketError.ConnectionAborted on Windows. // A connection reset can be reported as SocketError.ConnectionAborted on Windows.
// ProtocolType can be removed once https://github.com/dotnet/corefx/issues/31927 is fixed.
return errorCode == SocketError.ConnectionReset || return errorCode == SocketError.ConnectionReset ||
errorCode == SocketError.ConnectionAborted || errorCode == SocketError.Shutdown ||
errorCode == SocketError.Shutdown; (errorCode == SocketError.ConnectionAborted && IsWindows) ||
(errorCode == SocketError.ProtocolType && IsMacOS);
} }
private static bool IsConnectionAbortError(SocketError errorCode) private static bool IsConnectionAbortError(SocketError errorCode)
@ -337,7 +339,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal
// Calling Dispose after ReceiveAsync can cause an "InvalidArgument" error on *nix. // Calling Dispose after ReceiveAsync can cause an "InvalidArgument" error on *nix.
return errorCode == SocketError.OperationAborted || return errorCode == SocketError.OperationAborted ||
errorCode == SocketError.Interrupted || errorCode == SocketError.Interrupted ||
errorCode == SocketError.InvalidArgument; (errorCode == SocketError.InvalidArgument && !IsWindows);
} }
} }
} }