diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs index 26f3ed4ac3..670503dbda 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConnection.cs @@ -162,7 +162,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal handle.Libuv.Check(status, out var uvError); // Log connection resets at a lower (Debug) level. - if (status == LibuvConstants.ECONNRESET) + if (LibuvConstants.IsConnectionReset(status)) { Log.ConnectionReset(ConnectionId); error = new ConnectionResetException(uvError.Message, uvError); diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvConstants.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvConstants.cs index 1e7c8f319d..650700ec00 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvConstants.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvConstants.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal @@ -13,6 +14,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public static readonly int? ECONNRESET = GetECONNRESET(); public static readonly int? EADDRINUSE = GetEADDRINUSE(); public static readonly int? ENOTSUP = GetENOTSUP(); + public static readonly int? EPIPE = GetEPIPE(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool IsConnectionReset(int errno) + { + return errno == ECONNRESET || errno == EPIPE; + } private static int? GetECONNRESET() { @@ -31,6 +39,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal return null; } + private static int? GetEPIPE() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return -32; + } + + return null; + } + private static int? GetEADDRINUSE() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) diff --git a/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs b/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs index 92b3febcd7..ccf1362b6f 100644 --- a/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs +++ b/src/Kestrel.Transport.Libuv/Internal/LibuvOutputConsumer.cs @@ -118,7 +118,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal else { // Log connection resets at a lower (Debug) level. - if (status == LibuvConstants.ECONNRESET) + if (LibuvConstants.IsConnectionReset(status)) { _log.ConnectionReset(_connectionId); }