Skip to content

Commit

Permalink
#23: Prevent duplicate providers (#24)
Browse files Browse the repository at this point in the history
~ Add locking to maybe ensure that providers are not registered more than once. More testing will be needed to determine why there are more than one to begin with.
  • Loading branch information
nikita-petko committed Jun 18, 2024
1 parent 1360e5a commit 06a96c2
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions src/configuration/configuration/Implementation/VaultProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,17 @@ protected VaultProvider(ILogger logger = null)

_logger?.Debug("VaultProvider: Setup for '{0}/{1}' to refresh every '{2}' interval!", Mount, Path, RefreshInterval);

_providers.Add(this);
lock (_providers)
{
if (_providers.Contains(this))
{
_logger?.Debug("VaultProvider: Skipping setup for '{0}/{1}' because it is already setup!", Mount, Path);

return;
}

_providers.Add(this);
}

DoRefresh();
}
Expand All @@ -173,21 +183,24 @@ private static void RefreshThread()
{
while (true)
{
var providers = _providers.ToArray();

foreach (var provider in providers)
lock (_providers)
{
try
{
provider.DoRefresh();
}
catch (Exception ex)
var providers = _providers.ToArray();

foreach (var provider in providers)
{
_staticLogger?.Error(ex);
try
{
provider.DoRefresh();
}
catch (Exception ex)
{
_staticLogger?.Error(ex);
}
}
}

Thread.Sleep(RefreshInterval); // SetClient makes DoRefresh call.
Thread.Sleep(RefreshInterval); // SetClient makes DoRefresh call.
}
}
}

Expand Down

0 comments on commit 06a96c2

Please sign in to comment.