Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Fix HTTP 500 error in admin which could happen due to race condition

Leendert de Borst70360e603b34
diff --git a/apps/server/AliasVault.Admin/Services/VersionedContentService.cs b/apps/server/AliasVault.Admin/Services/VersionedContentService.cs
index eea016b3c..290d680f6 100644
--- a/apps/server/AliasVault.Admin/Services/VersionedContentService.cs
+++ b/apps/server/AliasVault.Admin/Services/VersionedContentService.cs
@@ -7,6 +7,7 @@
namespace AliasVault.Admin.Services;
+using System.Collections.Concurrent;
using System.Security.Cryptography;
/// <summary>
@@ -14,7 +15,7 @@ using System.Security.Cryptography;
/// </summary>
public class VersionedContentService
{
- private readonly Dictionary<string, string> _hashCache = new();
+ private readonly ConcurrentDictionary<string, string> _hashCache = new();
private readonly string _webRootPath;
/// <summary>
@@ -34,13 +35,7 @@ public class VersionedContentService
/// <returns>Path with version suffix added.</returns>
public string GetVersionedPath(string contentPath)
{
- if (!_hashCache.TryGetValue(contentPath, out var version))
- {
- var serverPath = Path.Combine(_webRootPath, contentPath.TrimStart('/'));
- version = GetVersionHashFrom(serverPath);
- _hashCache[contentPath] = version;
- }
-
+ var version = _hashCache.GetOrAdd(contentPath, path => GetVersionHashFrom(Path.Combine(_webRootPath, path.TrimStart('/'))));
return $"{contentPath}?v={version}";
}