mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-04-24 22:17:25 -04:00
Don't close the socket response multiple times
This commit is contained in:
parent
4a3e42e779
commit
6e07eab247
1 changed files with 5 additions and 18 deletions
|
@ -129,6 +129,7 @@ namespace Jellyfin.Server.SocketSharp
|
||||||
|
|
||||||
private async Task ProcessWebSocketRequest(HttpListenerContext ctx)
|
private async Task ProcessWebSocketRequest(HttpListenerContext ctx)
|
||||||
{
|
{
|
||||||
|
int statusCode = 200;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var endpoint = ctx.Request.RemoteEndPoint.ToString();
|
var endpoint = ctx.Request.RemoteEndPoint.ToString();
|
||||||
|
@ -164,33 +165,23 @@ namespace Jellyfin.Server.SocketSharp
|
||||||
Endpoint = endpoint
|
Endpoint = endpoint
|
||||||
});
|
});
|
||||||
|
|
||||||
await ReceiveWebSocketAsync(ctx, socket).ConfigureAwait(false);
|
await socket.StartReceive().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Web socket connection not allowed");
|
_logger.LogWarning("Web socket connection not allowed");
|
||||||
ctx.Response.StatusCode = 401;
|
statusCode = 401;
|
||||||
ctx.Response.Close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "AcceptWebSocketAsync error");
|
_logger.LogError(ex, "AcceptWebSocketAsync error");
|
||||||
ctx.Response.StatusCode = 500;
|
statusCode = 500;
|
||||||
ctx.Response.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task ReceiveWebSocketAsync(HttpListenerContext ctx, SharpWebSocket socket)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await socket.StartReceive().ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
TryClose(ctx, 200);
|
TryClose(ctx, statusCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,10 +192,6 @@ namespace Jellyfin.Server.SocketSharp
|
||||||
ctx.Response.StatusCode = statusCode;
|
ctx.Response.StatusCode = statusCode;
|
||||||
ctx.Response.Close();
|
ctx.Response.Close();
|
||||||
}
|
}
|
||||||
catch (ObjectDisposedException)
|
|
||||||
{
|
|
||||||
// TODO: Investigate and properly fix.
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Error closing web socket response");
|
_logger.LogError(ex, "Error closing web socket response");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue