diff --git a/src/Microsoft.AspNetCore.Sockets/ConnectionManager.cs b/src/Microsoft.AspNetCore.Sockets/ConnectionManager.cs index 1f3fe12169..0d23bc7161 100644 --- a/src/Microsoft.AspNetCore.Sockets/ConnectionManager.cs +++ b/src/Microsoft.AspNetCore.Sockets/ConnectionManager.cs @@ -5,6 +5,8 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; +using System.IO; +using System.Net.WebSockets; using System.Threading; using System.Threading.Tasks; using System.Threading.Tasks.Channels; @@ -178,6 +180,14 @@ namespace Microsoft.AspNetCore.Sockets { await connection.DisposeAsync(); } + catch (IOException ex) + { + _logger.ConnectionReset(connection.ConnectionId, ex); + } + catch (WebSocketException ex) when (ex.InnerException is IOException) + { + _logger.ConnectionReset(connection.ConnectionId, ex); + } catch (Exception ex) { _logger.FailedDispose(connection.ConnectionId, ex); diff --git a/src/Microsoft.AspNetCore.Sockets/Internal/SocketLoggerExtensions.cs b/src/Microsoft.AspNetCore.Sockets/Internal/SocketLoggerExtensions.cs index 7cd640e26f..8854633644 100644 --- a/src/Microsoft.AspNetCore.Sockets/Internal/SocketLoggerExtensions.cs +++ b/src/Microsoft.AspNetCore.Sockets/Internal/SocketLoggerExtensions.cs @@ -18,6 +18,9 @@ namespace Microsoft.AspNetCore.Sockets.Internal private static readonly Action _failedDispose = LoggerMessage.Define(LogLevel.Error, 2, "{time}: ConnectionId {connectionId}: Failed disposing connection."); + private static readonly Action _connectionReset = + LoggerMessage.Define(LogLevel.Trace, 3, "{time}: ConnectionId {connectionId}: Connection was reset."); + public static void CreatedNewConnection(this ILogger logger, string connectionId) { if (logger.IsEnabled(LogLevel.Debug)) @@ -41,5 +44,13 @@ namespace Microsoft.AspNetCore.Sockets.Internal _failedDispose(logger, DateTime.Now, connectionId, exception); } } + + public static void ConnectionReset(this ILogger logger, string connectionId, Exception exception) + { + if (logger.IsEnabled(LogLevel.Trace)) + { + _connectionReset(logger, DateTime.Now, connectionId, exception); + } + } } }