Fix concurrency issues

This commit is contained in:
Patrick Barron 2021-06-18 17:06:38 -04:00
parent 373155a063
commit 3d9c16ba6b
2 changed files with 8 additions and 7 deletions

View File

@ -15,12 +15,12 @@ namespace Jellyfin.Server.Implementations.Security
{ {
public class AuthorizationContext : IAuthorizationContext public class AuthorizationContext : IAuthorizationContext
{ {
private readonly JellyfinDb _jellyfinDb; private readonly JellyfinDbProvider _jellyfinDbProvider;
private readonly IUserManager _userManager; private readonly IUserManager _userManager;
public AuthorizationContext(JellyfinDb jellyfinDb, IUserManager userManager) public AuthorizationContext(JellyfinDbProvider jellyfinDb, IUserManager userManager)
{ {
_jellyfinDb = jellyfinDb; _jellyfinDbProvider = jellyfinDb;
_userManager = userManager; _userManager = userManager;
} }
@ -117,7 +117,8 @@ namespace Jellyfin.Server.Implementations.Security
#pragma warning restore CA1508 #pragma warning restore CA1508
authInfo.HasToken = true; authInfo.HasToken = true;
var device = await _jellyfinDb.Devices.FirstOrDefaultAsync(d => d.AccessToken == token).ConfigureAwait(false); await using var jellyfinDb = _jellyfinDbProvider.CreateContext();
var device = await jellyfinDb.Devices.FirstOrDefaultAsync(d => d.AccessToken == token).ConfigureAwait(false);
if (device != null) if (device != null)
{ {
@ -186,8 +187,8 @@ namespace Jellyfin.Server.Implementations.Security
if (updateToken) if (updateToken)
{ {
_jellyfinDb.Devices.Update(device); jellyfinDb.Devices.Update(device);
await _jellyfinDb.SaveChangesAsync().ConfigureAwait(false); await jellyfinDb.SaveChangesAsync().ConfigureAwait(false);
} }
} }

View File

@ -95,7 +95,7 @@ namespace Jellyfin.Server
ServiceCollection.AddSingleton<IWebSocketListener, ScheduledTasksWebSocketListener>(); ServiceCollection.AddSingleton<IWebSocketListener, ScheduledTasksWebSocketListener>();
ServiceCollection.AddSingleton<IWebSocketListener, SessionInfoWebSocketListener>(); ServiceCollection.AddSingleton<IWebSocketListener, SessionInfoWebSocketListener>();
ServiceCollection.AddScoped<IAuthorizationContext, AuthorizationContext>(); ServiceCollection.AddSingleton<IAuthorizationContext, AuthorizationContext>();
base.RegisterServices(); base.RegisterServices();
} }