diff --git a/src/SignalR/clients/csharp/Http.Connections.Client/src/Internal/WebSocketsTransport.Log.cs b/src/SignalR/clients/csharp/Http.Connections.Client/src/Internal/WebSocketsTransport.Log.cs index 31d8859f9f..5012d65d64 100644 --- a/src/SignalR/clients/csharp/Http.Connections.Client/src/Internal/WebSocketsTransport.Log.cs +++ b/src/SignalR/clients/csharp/Http.Connections.Client/src/Internal/WebSocketsTransport.Log.cs @@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Client.Internal LoggerMessage.Define(LogLevel.Information, new EventId(16, "ClosingWebSocket"), "Closing WebSocket."); private static readonly Action _closingWebSocketFailed = - LoggerMessage.Define(LogLevel.Information, new EventId(17, "ClosingWebSocketFailed"), "Closing webSocket failed."); + LoggerMessage.Define(LogLevel.Debug, new EventId(17, "ClosingWebSocketFailed"), "Closing webSocket failed."); private static readonly Action _cancelMessage = LoggerMessage.Define(LogLevel.Debug, new EventId(18, "CancelMessage"), "Canceled passing message to application."); diff --git a/src/SignalR/clients/csharp/Http.Connections.Client/src/Internal/WebSocketsTransport.cs b/src/SignalR/clients/csharp/Http.Connections.Client/src/Internal/WebSocketsTransport.cs index e4b395818d..905a965841 100644 --- a/src/SignalR/clients/csharp/Http.Connections.Client/src/Internal/WebSocketsTransport.cs +++ b/src/SignalR/clients/csharp/Http.Connections.Client/src/Internal/WebSocketsTransport.cs @@ -269,10 +269,6 @@ namespace Microsoft.AspNetCore.Http.Connections.Client.Internal if (!_aborted) { _application.Output.Complete(ex); - - // We re-throw here so we can communicate that there was an error when sending - // the close frame - throw; } } finally @@ -347,8 +343,15 @@ namespace Microsoft.AspNetCore.Http.Connections.Client.Internal { if (WebSocketCanSend(socket)) { - // We're done sending, send the close frame to the client if the websocket is still open - await socket.CloseOutputAsync(error != null ? WebSocketCloseStatus.InternalServerError : WebSocketCloseStatus.NormalClosure, "", CancellationToken.None); + try + { + // We're done sending, send the close frame to the client if the websocket is still open + await socket.CloseOutputAsync(error != null ? WebSocketCloseStatus.InternalServerError : WebSocketCloseStatus.NormalClosure, "", CancellationToken.None); + } + catch (Exception ex) + { + Log.ClosingWebSocketFailed(_logger, ex); + } } _application.Input.Complete(); diff --git a/src/SignalR/common/Http.Connections/src/Internal/Transports/WebSocketsServerTransport.cs b/src/SignalR/common/Http.Connections/src/Internal/Transports/WebSocketsServerTransport.cs index d9e5a90753..b8a3be18ef 100644 --- a/src/SignalR/common/Http.Connections/src/Internal/Transports/WebSocketsServerTransport.cs +++ b/src/SignalR/common/Http.Connections/src/Internal/Transports/WebSocketsServerTransport.cs @@ -189,10 +189,6 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal.Transports if (!_aborted && !token.IsCancellationRequested) { _application.Output.Complete(ex); - - // We re-throw here so we can communicate that there was an error when sending - // the close frame - throw; } } finally @@ -270,8 +266,15 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal.Transports // Send the close frame before calling into user code if (WebSocketCanSend(socket)) { - // We're done sending, send the close frame to the client if the websocket is still open - await socket.CloseOutputAsync(error != null ? WebSocketCloseStatus.InternalServerError : WebSocketCloseStatus.NormalClosure, "", CancellationToken.None); + try + { + // We're done sending, send the close frame to the client if the websocket is still open + await socket.CloseOutputAsync(error != null ? WebSocketCloseStatus.InternalServerError : WebSocketCloseStatus.NormalClosure, "", CancellationToken.None); + } + catch (Exception ex) + { + Log.ClosingWebSocketFailed(_logger, ex); + } } _application.Input.Complete(); diff --git a/src/SignalR/common/Http.Connections/src/Internal/Transports/WebSocketsTransport.Log.cs b/src/SignalR/common/Http.Connections/src/Internal/Transports/WebSocketsTransport.Log.cs index a3888977c2..75a2438f62 100644 --- a/src/SignalR/common/Http.Connections/src/Internal/Transports/WebSocketsTransport.Log.cs +++ b/src/SignalR/common/Http.Connections/src/Internal/Transports/WebSocketsTransport.Log.cs @@ -53,6 +53,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal.Transports private static readonly Action _closedPrematurely = LoggerMessage.Define(LogLevel.Debug, new EventId(14, "ClosedPrematurely"), "Socket connection closed prematurely."); + private static readonly Action _closingWebSocketFailed = + LoggerMessage.Define(LogLevel.Debug, new EventId(15, "ClosingWebSocketFailed"), "Closing webSocket failed."); + public static void SocketOpened(ILogger logger, string subProtocol) { _socketOpened(logger, subProtocol, null); @@ -122,6 +125,11 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal.Transports { _closedPrematurely(logger, ex); } + + public static void ClosingWebSocketFailed(ILogger logger, Exception ex) + { + _closingWebSocketFailed(logger, ex); + } } } }