Prevent payout processors from stalling restart

This commit is contained in:
nicolas.dorier
2023-04-26 18:09:56 +09:00
parent 4991d0f965
commit 5c91e072a6
8 changed files with 17 additions and 19 deletions

View File

@@ -32,7 +32,7 @@ namespace BTCPayServer.HostedServices
foreach (var t in _Tasks)
t.ContinueWith(t =>
{
if (t.IsFaulted)
if (t.IsFaulted && !CancellationToken.IsCancellationRequested)
Logs.PayServer.LogWarning(t.Exception, $"Unhanded exception in {this.GetType().Name}");
}, TaskScheduler.Default);
return Task.CompletedTask;
@@ -40,7 +40,7 @@ namespace BTCPayServer.HostedServices
internal abstract Task[] InitializeTasks();
protected CancellationToken Cancellation
protected CancellationToken CancellationToken
{
get { return _Cts.Token; }
}
@@ -69,8 +69,6 @@ namespace BTCPayServer.HostedServices
}
}
public CancellationToken CancellationToken => _Cts.Token;
public virtual async Task StopAsync(CancellationToken cancellationToken)
{
if (_Cts != null)

View File

@@ -28,8 +28,8 @@ namespace BTCPayServer.HostedServices
{
while (true)
{
await _transactionBroadcaster.ProcessAll(Cancellation);
await Task.Delay(PollInternal, Cancellation);
await _transactionBroadcaster.ProcessAll(CancellationToken);
await Task.Delay(PollInternal, CancellationToken);
}
}
}

View File

@@ -30,7 +30,7 @@ namespace BTCPayServer.HostedServices
readonly TimeSpan Period = TimeSpan.FromMinutes(60);
async Task UpdateRecord()
{
using (var timeout = CancellationTokenSource.CreateLinkedTokenSource(Cancellation))
using (var timeout = CancellationTokenSource.CreateLinkedTokenSource(CancellationToken))
{
var settings = await SettingsRepository.GetSettingAsync<DynamicDnsSettings>() ?? new DynamicDnsSettings();
foreach (var service in settings.Services)
@@ -59,9 +59,9 @@ namespace BTCPayServer.HostedServices
}
}
}
using var delayCancel = CancellationTokenSource.CreateLinkedTokenSource(Cancellation);
using var delayCancel = CancellationTokenSource.CreateLinkedTokenSource(CancellationToken);
var delay = Task.Delay(Period, delayCancel.Token);
var changed = SettingsRepository.WaitSettingsChanged<DynamicDnsSettings>(Cancellation);
var changed = SettingsRepository.WaitSettingsChanged<DynamicDnsSettings>(CancellationToken);
await Task.WhenAny(delay, changed);
delayCancel.Cancel();
}

View File

@@ -44,7 +44,7 @@ namespace BTCPayServer.HostedServices
{
Logs.Events.LogError(ex, "Error while performing new version check");
}
await Task.Delay(TimeSpan.FromDays(1), Cancellation);
await Task.Delay(TimeSpan.FromDays(1), CancellationToken);
}
public async Task ProcessVersionCheck()
@@ -52,7 +52,7 @@ namespace BTCPayServer.HostedServices
var policies = await _settingsRepository.GetSettingAsync<PoliciesSettings>() ?? new PoliciesSettings();
if (policies.CheckForNewVersions)
{
var tag = await _versionFetcher.Fetch(Cancellation);
var tag = await _versionFetcher.Fetch(CancellationToken);
if (tag != null && tag != _env.Version)
{
var dh = await _settingsRepository.GetSettingAsync<NewVersionCheckerDataHolder>() ?? new NewVersionCheckerDataHolder();

View File

@@ -64,10 +64,10 @@ namespace BTCPayServer.HostedServices
var usedProviders = GetStillUsedProviders().ToArray();
if (usedProviders.Length == 0)
{
await Task.Delay(TimeSpan.FromSeconds(30), Cancellation);
await Task.Delay(TimeSpan.FromSeconds(30), CancellationToken);
return;
}
using (var timeout = CancellationTokenSource.CreateLinkedTokenSource(Cancellation))
using (var timeout = CancellationTokenSource.CreateLinkedTokenSource(CancellationToken))
{
timeout.CancelAfter(TimeSpan.FromSeconds(20.0));
try
@@ -97,7 +97,7 @@ namespace BTCPayServer.HostedServices
await SaveRateCache();
}
}
await Task.Delay(TimeSpan.FromSeconds(30), Cancellation);
await Task.Delay(TimeSpan.FromSeconds(30), CancellationToken);
}
public override async Task StartAsync(CancellationToken cancellationToken)

View File

@@ -101,7 +101,7 @@ public class LightningPendingPayoutListener : BaseAsyncService
break;
case PayoutLightningBlob payoutLightningBlob:
{
var payment = await client.GetPayment(payoutLightningBlob.Id, Cancellation);
var payment = await client.GetPayment(payoutLightningBlob.Id, CancellationToken);
if (payment is null)
{
continue;
@@ -126,8 +126,8 @@ public class LightningPendingPayoutListener : BaseAsyncService
}
}
await context.SaveChangesAsync(Cancellation);
await Task.Delay(TimeSpan.FromSeconds(SecondsDelay), Cancellation);
await context.SaveChangesAsync(CancellationToken);
await Task.Delay(TimeSpan.FromSeconds(SecondsDelay), CancellationToken);
}
internal override Task[] InitializeTasks()

View File

@@ -74,7 +74,7 @@ public abstract class BaseAutomatedPayoutProcessor<T> : BaseAsyncService where T
States = new[] { PayoutState.AwaitingPayment },
PaymentMethods = new[] { _PayoutProcesserSettings.PaymentMethod },
Stores = new[] { _PayoutProcesserSettings.StoreId }
}, context);
}, context, CancellationToken);
if (payouts.Any())
{
Logs.PayServer.LogInformation($"{payouts.Count} found to process. Starting (and after will sleep for {blob.Interval})");

View File

@@ -35,7 +35,7 @@ namespace BTCPayServer.Services
}
else
{
await Task.Delay(TimeSpan.FromSeconds(120), Cancellation);
await Task.Delay(TimeSpan.FromSeconds(120), CancellationToken);
}
List<TorService> result = new List<TorService>();
try