mirror of https://github.com/jellyfin/jellyfin.git
put a lock around refresh ops
This commit is contained in:
parent
97582cef4f
commit
8a15ee6ab4
|
@ -24,6 +24,8 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||||
{
|
{
|
||||||
public class ConnectManager : IConnectManager
|
public class ConnectManager : IConnectManager
|
||||||
{
|
{
|
||||||
|
private SemaphoreSlim _operationLock = new SemaphoreSlim(1,1);
|
||||||
|
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IApplicationPaths _appPaths;
|
private readonly IApplicationPaths _appPaths;
|
||||||
private readonly IJsonSerializer _json;
|
private readonly IJsonSerializer _json;
|
||||||
|
@ -110,6 +112,20 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void UpdateConnectInfo()
|
private async void UpdateConnectInfo()
|
||||||
|
{
|
||||||
|
await _operationLock.WaitAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await UpdateConnectInfoInternal().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_operationLock.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task UpdateConnectInfoInternal()
|
||||||
{
|
{
|
||||||
var wanApiAddress = WanApiAddress;
|
var wanApiAddress = WanApiAddress;
|
||||||
|
|
||||||
|
@ -148,7 +164,7 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||||
await CreateServerRegistration(wanApiAddress).ConfigureAwait(false);
|
await CreateServerRegistration(wanApiAddress).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
await RefreshAuthorizations(CancellationToken.None).ConfigureAwait(false);
|
await RefreshAuthorizationsInternal(CancellationToken.None).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -439,6 +455,20 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RefreshAuthorizations(CancellationToken cancellationToken)
|
public async Task RefreshAuthorizations(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
await _operationLock.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await RefreshAuthorizationsInternal(cancellationToken).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_operationLock.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task RefreshAuthorizationsInternal(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var url = GetConnectUrl("ServerAuthorizations");
|
var url = GetConnectUrl("ServerAuthorizations");
|
||||||
|
|
||||||
|
@ -459,7 +489,6 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// No need to examine the response
|
|
||||||
using (var stream = (await _httpClient.SendAsync(options, "POST").ConfigureAwait(false)).Content)
|
using (var stream = (await _httpClient.SendAsync(options, "POST").ConfigureAwait(false)).Content)
|
||||||
{
|
{
|
||||||
var list = _json.DeserializeFromStream<List<ServerUserAuthorizationResponse>>(stream);
|
var list = _json.DeserializeFromStream<List<ServerUserAuthorizationResponse>>(stream);
|
||||||
|
@ -491,14 +520,12 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||||
user.ConnectAccessKey = null;
|
user.ConnectAccessKey = null;
|
||||||
user.ConnectUserName = null;
|
user.ConnectUserName = null;
|
||||||
|
|
||||||
|
await _userManager.UpdateUser(user).ConfigureAwait(false);
|
||||||
|
|
||||||
if (user.ConnectLinkType == UserLinkType.Guest)
|
if (user.ConnectLinkType == UserLinkType.Guest)
|
||||||
{
|
{
|
||||||
await _userManager.DeleteUser(user).ConfigureAwait(false);
|
await _userManager.DeleteUser(user).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
await _userManager.UpdateUser(user).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue