The Free Software Media System - Server Backend & API
integrate development from v1
herby2212db5c2f738efa
diff --cc Emby.Server.Implementations/Session/SessionManager.csindex e935f7e5e5,a6155aa621..b5d8f6c3b7--- a/Emby.Server.Implementations/Session/SessionManager.cs+++ b/Emby.Server.Implementations/Session/SessionManager.cs@@@ -45,9 -44,10 +46,10 @@@ namespace Emby.Server.Implementations.S/// <summary>/// Class SessionManager./// </summary>- public class SessionManager : ISessionManager, IDisposable+ public sealed class SessionManager : ISessionManager, IAsyncDisposable{private readonly IUserDataManager _userDataManager;+ private readonly IServerConfigurationManager _config;private readonly ILogger<SessionManager> _logger;private readonly IEventManager _eventManager;private readonly ILibraryManager _libraryManager;@@@ -58,11 -58,14 +60,12 @@@private readonly IMediaSourceManager _mediaSourceManager;private readonly IServerApplicationHost _appHost;private readonly IDeviceManager _deviceManager;-- /// <summary>- /// The active connections.- /// </summary>- private readonly ConcurrentDictionary<string, SessionInfo> _activeConnections = new(StringComparer.OrdinalIgnoreCase);+ private readonly CancellationTokenRegistration _shutdownCallback;+ private readonly ConcurrentDictionary<string, SessionInfo> _activeConnections+ = new(StringComparer.OrdinalIgnoreCase);private Timer _idleTimer;+ private Timer _inactiveTimer;private DtoOptions _itemInfoDtoOptions;private bool _disposed = false;@@@ -1778,53 -1924,5 +1853,59 @@@return SendMessageToSessions(sessions, name, data, cancellationToken);}++ /// <inheritdoc />+ public async ValueTask DisposeAsync()+ {+ if (_disposed)+ {+ return;+ }++ foreach (var session in _activeConnections.Values)+ {+ await session.DisposeAsync().ConfigureAwait(false);+ }++ if (_idleTimer is not null)+ {+ await _idleTimer.DisposeAsync().ConfigureAwait(false);+ _idleTimer = null;+ }+++ if(_inactiveTimer is not null)++ {++ await _inactiveTimer.DisposeAsync().ConfigureAwait(false);++ _inactiveTimer = null;++ }+++ await _shutdownCallback.DisposeAsync().ConfigureAwait(false);++ _deviceManager.DeviceOptionsUpdated -= OnDeviceManagerDeviceOptionsUpdated;+ _disposed = true;+ }++ private async void OnApplicationStopping()+ {+ _logger.LogInformation("Sending shutdown notifications");+ try+ {+ var messageType = _appHost.ShouldRestart ? SessionMessageType.ServerRestarting : SessionMessageType.ServerShuttingDown;++ await SendMessageToSessions(Sessions, messageType, string.Empty, CancellationToken.None).ConfigureAwait(false);+ }+ catch (Exception ex)+ {+ _logger.LogError(ex, "Error sending server shutdown notifications");+ }++ // Close open websockets to allow Kestrel to shut down cleanly+ foreach (var session in _activeConnections.Values)+ {+ await session.DisposeAsync().ConfigureAwait(false);+ }++ _activeConnections.Clear();+ }}}