attempt to remove coordinators when it's obviously down

This commit is contained in:
Andrew Camilleri
2025-03-31 13:05:13 +02:00
parent 3c741d29ff
commit 8390002e87
3 changed files with 28 additions and 10 deletions

View File

@@ -13,7 +13,7 @@
<PropertyGroup>
<Product>Coinjoin</Product>
<Description>Allows you to integrate your btcpayserver store with coinjoins.</Description>
<Version>1.0.104</Version>
<Version>1.0.105</Version>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

View File

@@ -338,7 +338,8 @@ public class WabisabiCoordinatorClientInstance:IHostedService
});
}
WasabiCoordinatorStatusFetcher = new WasabiCoordinatorStatusFetcher(sharedWabisabiClient, _logger);
WasabiCoordinatorStatusFetcher = new WasabiCoordinatorStatusFetcher(sharedWabisabiClient, _logger, () => serviceProvider.GetService<WabisabiCoordinatorClientInstanceManager>().RemoveCoordinator(this.CoordinatorName) );
RoundStateUpdater =
new RoundStateUpdater(TimeSpan.FromSeconds(5), sharedWabisabiClient, WasabiCoordinatorStatusFetcher);

View File

@@ -2,6 +2,7 @@
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using WalletWasabi.Bases;
using WalletWasabi.WabiSabi.Backend.PostRequests;
@@ -14,15 +15,20 @@ public class WasabiCoordinatorStatusFetcher : PeriodicRunner, IWasabiBackendStat
{
private readonly IWabiSabiApiRequestHandler _wasabiClient;
private readonly ILogger _logger;
private readonly Action _onRemove;
public bool Connected { get; set; } = false;
public bool? OverrideConnected { get; set; }
public WasabiCoordinatorStatusFetcher(IWabiSabiApiRequestHandler wasabiClient, ILogger logger) :
public WasabiCoordinatorStatusFetcher(IWabiSabiApiRequestHandler wasabiClient, ILogger logger, Action onRemove) :
base(TimeSpan.FromSeconds(30))
{
_wasabiClient = wasabiClient;
_logger = logger;
_onRemove = onRemove;
}
private int _retries = 0;
protected override async Task ActionAsync(CancellationToken cancel)
{
try
@@ -33,19 +39,30 @@ public class WasabiCoordinatorStatusFetcher : PeriodicRunner, IWasabiBackendStat
}
else
{
await _wasabiClient.GetStatusAsync(new RoundStateRequest(ImmutableList<RoundStateCheckpoint>.Empty), cancel);
var cts = CancellationTokenSource.CreateLinkedTokenSource(cancel);
cts.CancelAfter(30000);
await _wasabiClient.GetStatusAsync(new RoundStateRequest(ImmutableList<RoundStateCheckpoint>.Empty),
cts.Token);
if (!Connected)
{
_logger.LogInformation("Connected to coordinator");
}
Connected = true;
_retries = 0;
}
}
catch (Exception e)
{
Connected = false;
_retries++;
if (_retries > 5)
{
_logger.LogError(e, "Could not connect to the coordinator after 5 retries, removing from the system");
_onRemove.Invoke();
}
await Task.Delay(Period * _retries, cancel);
throw new Exception("Could not connect to the coordinator", e);
}
}