mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 12:59:39 -07:00
Added a global mutex (not used yet) and moved around the code for loggin in since I suspect the Get Roles call is using deffered execution on the database causing the lock when attempting to access straight away #2750
This commit is contained in:
parent
12997541f0
commit
1322076aa6
2 changed files with 41 additions and 3 deletions
38
src/Ombi.Helpers/GlobalMutex.cs
Normal file
38
src/Ombi.Helpers/GlobalMutex.cs
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace Ombi.Helpers
|
||||||
|
{
|
||||||
|
public static class GlobalMutex
|
||||||
|
{
|
||||||
|
public static T Lock<T>(Func<T> func)
|
||||||
|
{
|
||||||
|
const string mutexId = "Global\\OMBI";
|
||||||
|
|
||||||
|
using (var mutex = new Mutex(false, mutexId, out __))
|
||||||
|
{
|
||||||
|
var hasHandle = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
hasHandle = mutex.WaitOne(5000, false);
|
||||||
|
if (hasHandle == false)
|
||||||
|
throw new TimeoutException("Timeout waiting for exclusive access");
|
||||||
|
}
|
||||||
|
catch (AbandonedMutexException)
|
||||||
|
{
|
||||||
|
hasHandle = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return func();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (hasHandle)
|
||||||
|
mutex.ReleaseMutex();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -123,9 +123,6 @@ namespace Ombi.Controllers
|
||||||
return new UnauthorizedResult();
|
return new UnauthorizedResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
user.LastLoggedIn = DateTime.UtcNow;
|
|
||||||
await _userManager.UpdateAsync(user);
|
|
||||||
|
|
||||||
var claims = new List<Claim>
|
var claims = new List<Claim>
|
||||||
{
|
{
|
||||||
new Claim(JwtRegisteredClaimNames.Sub, user.UserName),
|
new Claim(JwtRegisteredClaimNames.Sub, user.UserName),
|
||||||
|
@ -152,6 +149,9 @@ namespace Ombi.Controllers
|
||||||
//await _token.CreateToken(new Tokens() {Token = accessToken, User = user});
|
//await _token.CreateToken(new Tokens() {Token = accessToken, User = user});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
user.LastLoggedIn = DateTime.UtcNow;
|
||||||
|
await _userManager.UpdateAsync(user);
|
||||||
|
|
||||||
return new JsonResult(new
|
return new JsonResult(new
|
||||||
{
|
{
|
||||||
access_token = accessToken,
|
access_token = accessToken,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue