mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 18:11:36 +01:00
prevent watcher loop to crash
This commit is contained in:
parent
62e3f2d8e1
commit
76993d2532
@ -2,7 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<Version>1.0.0.9</Version>
|
||||
<Version>1.0.0.10</Version>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Remove="Build\dockerfiles\**" />
|
||||
|
@ -281,12 +281,12 @@ namespace BTCPayServer.Servcices.Invoices
|
||||
{
|
||||
Logs.PayServer.LogInformation("Start watching invoices");
|
||||
ConcurrentDictionary<string, Lazy<Task>> updating = new ConcurrentDictionary<string, Lazy<Task>>();
|
||||
try
|
||||
foreach(var item in _WatchRequests.GetConsumingEnumerable(_Cts.Token))
|
||||
{
|
||||
foreach(var item in _WatchRequests.GetConsumingEnumerable(_Cts.Token))
|
||||
try
|
||||
{
|
||||
_Cts.Token.ThrowIfCancellationRequested();
|
||||
var localItem = item;
|
||||
|
||||
// If the invoice is already updating, ignore
|
||||
Lazy<Task> updateInvoice = new Lazy<Task>(() => UpdateInvoice(localItem), false);
|
||||
if(updating.TryAdd(item, updateInvoice))
|
||||
@ -294,26 +294,23 @@ namespace BTCPayServer.Servcices.Invoices
|
||||
updateInvoice.Value.ContinueWith(i => updating.TryRemove(item, out updateInvoice));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(OperationCanceledException) when(_Cts.Token.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
catch(OperationCanceledException) when(_Cts.Token.IsCancellationRequested)
|
||||
{
|
||||
Task.WaitAll(updating.Select(c => c.Value.Value).ToArray());
|
||||
try
|
||||
{
|
||||
Task.WaitAll(updating.Select(c => c.Value.Value).ToArray());
|
||||
}
|
||||
catch(AggregateException) { }
|
||||
_RunningTask.TrySetResult(true);
|
||||
break;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Logs.PayServer.LogCritical(ex, "Error in the InvoiceWatcher loop");
|
||||
_Cts.Token.WaitHandle.WaitOne(2000);
|
||||
}
|
||||
catch(AggregateException) { }
|
||||
_RunningTask.TrySetResult(true);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
_Cts.Cancel();
|
||||
_RunningTask.TrySetException(ex);
|
||||
Logs.PayServer.LogCritical(ex, "Error in the InvoiceWatcher loop");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Logs.PayServer.LogInformation("Stop watching invoices");
|
||||
}
|
||||
Logs.PayServer.LogInformation("Stop watching invoices");
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user