Capture and log prematurely closed connections

This commit is contained in:
James Newton-King 2018-04-16 10:41:35 +12:00
parent fbb13c4c1f
commit 62f14054eb
No known key found for this signature in database
GPG Key ID: 0A66B2F456BF5526
2 changed files with 10 additions and 6 deletions

View File

@ -50,6 +50,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal.Transports
private static readonly Action<ILogger, Exception> _sendFailed =
LoggerMessage.Define(LogLevel.Error, new EventId(13, "SendFailed"), "Socket failed to send.");
private static readonly Action<ILogger, Exception> _closedPrematurely =
LoggerMessage.Define(LogLevel.Debug, new EventId(14, "ClosedPrematurely"), "Socket connection closed prematurely.");
public static void SocketOpened(ILogger logger, string subProtocol)
{
_socketOpened(logger, subProtocol, null);
@ -115,6 +118,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal.Transports
_sendFailed(logger, ex);
}
public static void ClosedPrematurely(ILogger logger, Exception ex)
{
_closedPrematurely(logger, ex);
}
}
}
}

View File

@ -182,13 +182,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal.Transports
}
}
}
catch (WebSocketException ex) when (
ex.ErrorCode == 997 ||
// Sometimes this error is raised without the ErrorCode
ex.Message == "The remote party closed the WebSocket connection without completing the close handshake.")
catch (WebSocketException ex) when (ex.WebSocketErrorCode == WebSocketError.ConnectionClosedPrematurely)
{
// The remote party closed the WebSocket connection without completing the close handshake
// Don't long an error for this exception
// Client has closed the WebSocket connection without completing the close handshake
Log.ClosedPrematurely(_logger, ex);
}
catch (OperationCanceledException)
{