aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBond-009 <bond.009@outlook.com>2019-12-27 15:42:59 +0100
committerBond_009 <bond.009@outlook.com>2020-01-13 20:06:08 +0100
commitbdd823d22ff4d20e8aa2e5d8bf34e0faaad285ba (patch)
tree818b4c91376fe58bc31016d8fd623c3880910311
parent8865b3ea3d0af201c37aa129016b843f0b9fe686 (diff)
Handle unexpected disconnect
-rw-r--r--Emby.Server.Implementations/HttpServer/HttpListenerHost.cs2
-rw-r--r--Emby.Server.Implementations/HttpServer/WebSocketConnection.cs11
2 files changed, 11 insertions, 2 deletions
diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
index 3cdb0ecae..05dbad624 100644
--- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
+++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
@@ -540,7 +540,7 @@ namespace Emby.Server.Implementations.HttpServer
}
catch (Exception ex) // Otherwise ASP.Net will ignore the exception
{
- _logger.LogError(ex, "WS {IP} WebSocketRequestHandler error");
+ _logger.LogError(ex, "WS {IP} WebSocketRequestHandler error", context.Connection.RemoteIpAddress);
if (!context.Response.HasStarted)
{
context.Response.StatusCode = 500;
diff --git a/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs b/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs
index 0afd0ecce..7c0d82d89 100644
--- a/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs
+++ b/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs
@@ -116,7 +116,16 @@ namespace Emby.Server.Implementations.HttpServer
{
// Allocate at least 512 bytes from the PipeWriter
Memory<byte> memory = writer.GetMemory(512);
- receiveresult = await _socket.ReceiveAsync(memory, cancellationToken);
+ try
+ {
+ receiveresult = await _socket.ReceiveAsync(memory, cancellationToken);
+ }
+ catch (WebSocketException ex)
+ {
+ _logger.LogWarning("WS {IP} error receiving data: {Message}", RemoteEndPoint, ex.Message);
+ break;
+ }
+
int bytesRead = receiveresult.Count;
if (bytesRead == 0)
{