Skip to content

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

Remove semaphore as timer with cancellation token prevents race conditions (#240)

Leendert de Borstd3d6dc56b842
diff --git a/src/AliasVault.Admin/Main/Components/WorkerStatus/Services.razor b/src/AliasVault.Admin/Main/Components/WorkerStatus/Services.razor
index 2eb87568a..d5927a92f 100644
--- a/src/AliasVault.Admin/Main/Components/WorkerStatus/Services.razor
+++ b/src/AliasVault.Admin/Main/Components/WorkerStatus/Services.razor
@@ -27,11 +27,6 @@
/// </summary>
private readonly int AutoRefreshInterval = 5000;
- /// <summary>
- /// SemaphoreSlim to prevent concurrent execution of InitPage
- /// </summary>
- private SemaphoreSlim InitLock = new(1, 1);
-
/// <summary>
/// CancellationTokenSource for the timer.
/// </summary>
@@ -49,6 +44,9 @@
}
}
+ /// <summary>
+ /// Refreshes the service status periodically while waiting for specified amount of ms in between.
+ /// </summary>
private async Task RunPeriodicRefreshAsync(CancellationToken cancellationToken)
{
while (!cancellationToken.IsCancellationRequested)
@@ -67,7 +65,6 @@
{
_timerCancellationTokenSource?.Cancel();
_timerCancellationTokenSource?.Dispose();
- InitLock.Dispose();
}
}
@@ -138,33 +135,29 @@
/// </summary>
private async Task InitPage()
{
- if (await InitLock.WaitAsync(0))
+ if (InitInProgress || SmtpPending)
{
- try
- {
- if (InitInProgress || SmtpPending)
- {
- return;
- }
-
- InitInProgress = true;
- var dbContext = await DbContextFactory.CreateDbContextAsync();
- ServiceStatus = await dbContext.WorkerServiceStatuses.ToListAsync();
+ return;
+ }
- var smtpEntry = ServiceStatus.Find(x => x.ServiceName == "AliasVault.SmtpService");
- if (smtpEntry != null)
- {
- LastHeartbeat = smtpEntry.Heartbeat;
- SmtpStatus = IsHeartbeatValid() && smtpEntry.CurrentStatus == "Started";
- }
+ try
+ {
+ InitInProgress = true;
+ var dbContext = await DbContextFactory.CreateDbContextAsync();
+ ServiceStatus = await dbContext.WorkerServiceStatuses.ToListAsync();
- await InvokeAsync(StateHasChanged);
- }
- finally
+ var smtpEntry = ServiceStatus.Find(x => x.ServiceName == "AliasVault.SmtpService");
+ if (smtpEntry != null)
{
- InitInProgress = false;
- InitLock.Release();
+ LastHeartbeat = smtpEntry.Heartbeat;
+ SmtpStatus = IsHeartbeatValid() && smtpEntry.CurrentStatus == "Started";
}
+
+ await InvokeAsync(StateHasChanged);
+ }
+ finally
+ {
+ InitInProgress = false;
}
}