Capture and log prematurely closed connections
This commit is contained in:
parent
fbb13c4c1f
commit
62f14054eb
|
|
@ -50,6 +50,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal.Transports
|
||||||
private static readonly Action<ILogger, Exception> _sendFailed =
|
private static readonly Action<ILogger, Exception> _sendFailed =
|
||||||
LoggerMessage.Define(LogLevel.Error, new EventId(13, "SendFailed"), "Socket failed to send.");
|
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)
|
public static void SocketOpened(ILogger logger, string subProtocol)
|
||||||
{
|
{
|
||||||
_socketOpened(logger, subProtocol, null);
|
_socketOpened(logger, subProtocol, null);
|
||||||
|
|
@ -115,6 +118,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal.Transports
|
||||||
_sendFailed(logger, ex);
|
_sendFailed(logger, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ClosedPrematurely(ILogger logger, Exception ex)
|
||||||
|
{
|
||||||
|
_closedPrematurely(logger, ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -182,13 +182,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal.Transports
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (WebSocketException ex) when (
|
catch (WebSocketException ex) when (ex.WebSocketErrorCode == WebSocketError.ConnectionClosedPrematurely)
|
||||||
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.")
|
|
||||||
{
|
{
|
||||||
// The remote party closed the WebSocket connection without completing the close handshake
|
// Client has closed the WebSocket connection without completing the close handshake
|
||||||
// Don't long an error for this exception
|
Log.ClosedPrematurely(_logger, ex);
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue