diff options
| author | Mohammed Alhaddar <31822932+moalhaddar@users.noreply.github.com> | 2025-06-06 15:55:05 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-06 06:55:05 -0600 |
| commit | 97f9d0c7e6fca70a0ed3de280ee7f040aee01951 (patch) | |
| tree | 486a90e349f7be3fe2fd1841b525c25f3b8f8356 /Emby.Server.Implementations/Session/SessionManager.cs | |
| parent | 9ab22e9f8b7dd47ed6bd2dade2e8612c6a909ee2 (diff) | |
Fixing race condition in GetSessionInfo (#14131)
Diffstat (limited to 'Emby.Server.Implementations/Session/SessionManager.cs')
| -rw-r--r-- | Emby.Server.Implementations/Session/SessionManager.cs | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs index 924f50286..8cbd957a8 100644 --- a/Emby.Server.Implementations/Session/SessionManager.cs +++ b/Emby.Server.Implementations/Session/SessionManager.cs @@ -508,13 +508,11 @@ namespace Emby.Server.Implementations.Session ArgumentException.ThrowIfNullOrEmpty(deviceId); var key = GetSessionKey(appName, deviceId); - - CheckDisposed(); - - if (!_activeConnections.TryGetValue(key, out var sessionInfo)) + SessionInfo newSession = CreateSessionInfo(key, appName, appVersion, deviceId, deviceName, remoteEndPoint, user); + SessionInfo sessionInfo = _activeConnections.GetOrAdd(key, newSession); + if (ReferenceEquals(newSession, sessionInfo)) { - sessionInfo = CreateSession(key, appName, appVersion, deviceId, deviceName, remoteEndPoint, user); - _activeConnections[key] = sessionInfo; + OnSessionStarted(newSession); } sessionInfo.UserId = user?.Id ?? Guid.Empty; @@ -538,7 +536,7 @@ namespace Emby.Server.Implementations.Session return sessionInfo; } - private SessionInfo CreateSession( + private SessionInfo CreateSessionInfo( string key, string appName, string appVersion, @@ -582,7 +580,6 @@ namespace Emby.Server.Implementations.Session sessionInfo.HasCustomDeviceName = true; } - OnSessionStarted(sessionInfo); return sessionInfo; } |
