aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/HttpServer/WebSocketManager.cs
diff options
context:
space:
mode:
authorClaus Vium <cvium@users.noreply.github.com>2024-03-30 17:30:00 +0100
committerGitHub <noreply@github.com>2024-03-30 10:30:00 -0600
commit4201079b349c34372aa9375791aa86d7e90572f1 (patch)
tree94e72aad47f0390ff6e693b7771f6042635b4471 /Emby.Server.Implementations/HttpServer/WebSocketManager.cs
parentfe88a484d18ddbb2fb6859b93ff2e05a166359f1 (diff)
fix: use a reentrant lock when accessing active connections (#11256)
Diffstat (limited to 'Emby.Server.Implementations/HttpServer/WebSocketManager.cs')
-rw-r--r--Emby.Server.Implementations/HttpServer/WebSocketManager.cs20
1 files changed, 11 insertions, 9 deletions
diff --git a/Emby.Server.Implementations/HttpServer/WebSocketManager.cs b/Emby.Server.Implementations/HttpServer/WebSocketManager.cs
index 52f14b0b1..774d3563c 100644
--- a/Emby.Server.Implementations/HttpServer/WebSocketManager.cs
+++ b/Emby.Server.Implementations/HttpServer/WebSocketManager.cs
@@ -48,7 +48,7 @@ namespace Emby.Server.Implementations.HttpServer
WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync().ConfigureAwait(false);
- using var connection = new WebSocketConnection(
+ var connection = new WebSocketConnection(
_loggerFactory.CreateLogger<WebSocketConnection>(),
webSocket,
authorizationInfo,
@@ -56,17 +56,19 @@ namespace Emby.Server.Implementations.HttpServer
{
OnReceive = ProcessWebSocketMessageReceived
};
-
- var tasks = new Task[_webSocketListeners.Length];
- for (var i = 0; i < _webSocketListeners.Length; ++i)
+ await using (connection.ConfigureAwait(false))
{
- tasks[i] = _webSocketListeners[i].ProcessWebSocketConnectedAsync(connection, context);
- }
+ var tasks = new Task[_webSocketListeners.Length];
+ for (var i = 0; i < _webSocketListeners.Length; ++i)
+ {
+ tasks[i] = _webSocketListeners[i].ProcessWebSocketConnectedAsync(connection, context);
+ }
- await Task.WhenAll(tasks).ConfigureAwait(false);
+ await Task.WhenAll(tasks).ConfigureAwait(false);
- await connection.ReceiveAsync().ConfigureAwait(false);
- _logger.LogInformation("WS {IP} closed", context.Connection.RemoteIpAddress);
+ await connection.ReceiveAsync().ConfigureAwait(false);
+ _logger.LogInformation("WS {IP} closed", context.Connection.RemoteIpAddress);
+ }
}
catch (Exception ex) // Otherwise ASP.Net will ignore the exception
{