Fix concurrency issues

pull/6201/head
Patrick Barron 4 years ago
parent 373155a063
commit 3d9c16ba6b

@ -15,12 +15,12 @@ namespace Jellyfin.Server.Implementations.Security
{
public class AuthorizationContext : IAuthorizationContext
{
private readonly JellyfinDb _jellyfinDb;
private readonly JellyfinDbProvider _jellyfinDbProvider;
private readonly IUserManager _userManager;
public AuthorizationContext(JellyfinDb jellyfinDb, IUserManager userManager)
public AuthorizationContext(JellyfinDbProvider jellyfinDb, IUserManager userManager)
{
_jellyfinDb = jellyfinDb;
_jellyfinDbProvider = jellyfinDb;
_userManager = userManager;
}
@ -117,7 +117,8 @@ namespace Jellyfin.Server.Implementations.Security
#pragma warning restore CA1508
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)
{
@ -186,8 +187,8 @@ namespace Jellyfin.Server.Implementations.Security
if (updateToken)
{
_jellyfinDb.Devices.Update(device);
await _jellyfinDb.SaveChangesAsync().ConfigureAwait(false);
jellyfinDb.Devices.Update(device);
await jellyfinDb.SaveChangesAsync().ConfigureAwait(false);
}
}

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

Loading…
Cancel
Save