mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 11:34:57 +02:00
Fix web sockets closing ungracefully
This commit is contained in:
parent
39196bb5e2
commit
4b563f4d7e
6 changed files with 55 additions and 0 deletions
|
@ -889,6 +889,11 @@ namespace Emby.Dlna.PlayTo
|
|||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public void CloseAllWebSockets(CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private class StreamParams
|
||||
{
|
||||
private MediaSourceInfo _mediaSource;
|
||||
|
|
|
@ -231,6 +231,15 @@ namespace Emby.Server.Implementations.HttpServer
|
|||
CancellationToken.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gracefully closes the socket.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
public void CloseSocket(CancellationToken cancellationToken)
|
||||
{
|
||||
_socket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "System Shutdown", cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
|
|
|
@ -1363,9 +1363,26 @@ namespace Emby.Server.Implementations.Session
|
|||
{
|
||||
CheckDisposed();
|
||||
|
||||
CloseAllWebSockets(cancellationToken);
|
||||
|
||||
return SendMessageToSessions(Sessions, SessionMessageType.ServerShuttingDown, string.Empty, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gracefully closes all web sockets in all sessions.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
private void CloseAllWebSockets(CancellationToken cancellationToken)
|
||||
{
|
||||
foreach (var session in Sessions)
|
||||
{
|
||||
foreach (var sessionController in session.SessionControllers)
|
||||
{
|
||||
sessionController.CloseAllWebSockets(cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends the server restart notification.
|
||||
/// </summary>
|
||||
|
|
|
@ -88,6 +88,18 @@ namespace Emby.Server.Implementations.Session
|
|||
cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gracefully closes all web sockets.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
public void CloseAllWebSockets(CancellationToken cancellationToken)
|
||||
{
|
||||
foreach (var socket in _sockets)
|
||||
{
|
||||
socket.CloseSocket(cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
|
|
|
@ -58,5 +58,11 @@ namespace MediaBrowser.Controller.Net
|
|||
Task SendAsync<T>(WebSocketMessage<T> message, CancellationToken cancellationToken);
|
||||
|
||||
Task ProcessAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Gracefully closes the socket.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
void CloseSocket(CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,5 +33,11 @@ namespace MediaBrowser.Controller.Session
|
|||
/// <param name="cancellationToken">CancellationToken for operation.</param>
|
||||
/// <returns>A task.</returns>
|
||||
Task SendMessage<T>(SessionMessageType name, Guid messageId, T data, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gracefully closes all web sockets.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
void CloseAllWebSockets(CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue