mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 05:47:14 -04:00
cancel web socket operations on dispose
This commit is contained in:
parent
51a6ee5650
commit
df29ed5a6f
@ -25,6 +25,8 @@ namespace MediaBrowser.Server.Implementations.HttpServer
|
||||
/// <value>The web socket.</value>
|
||||
private System.Net.WebSockets.WebSocket WebSocket { get; set; }
|
||||
|
||||
private CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="NativeWebSocket" /> class.
|
||||
/// </summary>
|
||||
@ -79,7 +81,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
|
||||
|
||||
try
|
||||
{
|
||||
bytes = await ReceiveBytesAsync(CancellationToken.None).ConfigureAwait(false);
|
||||
bytes = await ReceiveBytesAsync(_cancellationTokenSource.Token).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
@ -144,7 +146,9 @@ namespace MediaBrowser.Server.Implementations.HttpServer
|
||||
_logger.Warn("Unrecognized WebSocketMessageType: {0}", type.ToString());
|
||||
}
|
||||
|
||||
return WebSocket.SendAsync(new ArraySegment<byte>(bytes), nativeType, true, cancellationToken);
|
||||
var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, _cancellationTokenSource.Token);
|
||||
|
||||
return WebSocket.SendAsync(new ArraySegment<byte>(bytes), nativeType, true, linkedTokenSource.Token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -163,6 +167,9 @@ namespace MediaBrowser.Server.Implementations.HttpServer
|
||||
{
|
||||
if (dispose)
|
||||
{
|
||||
_cancellationTokenSource.Cancel();
|
||||
_cancellationTokenSource.Dispose();
|
||||
|
||||
WebSocket.Dispose();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user