From 29d51ad2a2cdfad3e770b450255ecd6760731cbe Mon Sep 17 00:00:00 2001 From: rockstardev Date: Fri, 21 Feb 2020 02:14:49 -0600 Subject: [PATCH] Adding 1 second leeway for expiration --- BTCPayServer/HostedServices/InvoiceWatcher.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/BTCPayServer/HostedServices/InvoiceWatcher.cs b/BTCPayServer/HostedServices/InvoiceWatcher.cs index 85e62f071..105daf63e 100644 --- a/BTCPayServer/HostedServices/InvoiceWatcher.cs +++ b/BTCPayServer/HostedServices/InvoiceWatcher.cs @@ -54,7 +54,7 @@ namespace BTCPayServer.HostedServices private async Task UpdateInvoice(UpdateInvoiceContext context) { var invoice = context.Invoice; - if (invoice.Status == InvoiceStatus.New && invoice.ExpirationTime < DateTimeOffset.UtcNow) + if (invoice.Status == InvoiceStatus.New && invoice.ExpirationTime <= DateTimeOffset.UtcNow) { context.MarkDirty(); await _InvoiceRepository.UnaffectAddress(invoice.Id); @@ -192,13 +192,16 @@ namespace BTCPayServer.HostedServices var invoice = await _InvoiceRepository.GetInvoice(invoiceId); try { - var delay = invoice.ExpirationTime - DateTimeOffset.UtcNow; + // add 1 second to ensure watch won't trigger moments before invoice expires + var delay = invoice.ExpirationTime.AddSeconds(1) - DateTimeOffset.UtcNow; if (delay > TimeSpan.Zero) { await Task.Delay(delay, _Cts.Token); } Watch(invoiceId); - delay = invoice.MonitoringExpiration - DateTimeOffset.UtcNow; + + // add 1 second to ensure watch won't trigger moments before monitoring expires + delay = invoice.MonitoringExpiration.AddSeconds(1) - DateTimeOffset.UtcNow; if (delay > TimeSpan.Zero) { await Task.Delay(delay, _Cts.Token);