From 0bd02a9272d9c762c014754ecb3e475f38fdb044 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Wed, 27 Mar 2019 18:56:43 +0900 Subject: [PATCH] Fix some exceptions raised if port is already used --- .../HostedServices/BackgroundJobSchedulerHostedService.cs | 2 ++ BTCPayServer/HostedServices/BaseAsyncService.cs | 2 ++ BTCPayServer/HostedServices/InvoiceWatcher.cs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/BTCPayServer/HostedServices/BackgroundJobSchedulerHostedService.cs b/BTCPayServer/HostedServices/BackgroundJobSchedulerHostedService.cs index 1689e74af..98e547f80 100644 --- a/BTCPayServer/HostedServices/BackgroundJobSchedulerHostedService.cs +++ b/BTCPayServer/HostedServices/BackgroundJobSchedulerHostedService.cs @@ -34,6 +34,8 @@ namespace BTCPayServer.HostedServices public async Task StopAsync(CancellationToken cancellationToken) { + if (_Stop == null) + return Task.CompletedTask; _Stop.Cancel(); try { diff --git a/BTCPayServer/HostedServices/BaseAsyncService.cs b/BTCPayServer/HostedServices/BaseAsyncService.cs index 4b8c85512..1bc6ca2ec 100644 --- a/BTCPayServer/HostedServices/BaseAsyncService.cs +++ b/BTCPayServer/HostedServices/BaseAsyncService.cs @@ -59,6 +59,8 @@ namespace BTCPayServer.HostedServices public Task StopAsync(CancellationToken cancellationToken) { + if (_Cts == null) + return Task.CompletedTask; _Cts.Cancel(); return Task.WhenAll(_Tasks); } diff --git a/BTCPayServer/HostedServices/InvoiceWatcher.cs b/BTCPayServer/HostedServices/InvoiceWatcher.cs index 4e62f3d24..ec413dc2d 100644 --- a/BTCPayServer/HostedServices/InvoiceWatcher.cs +++ b/BTCPayServer/HostedServices/InvoiceWatcher.cs @@ -333,6 +333,8 @@ namespace BTCPayServer.HostedServices public Task StopAsync(CancellationToken cancellationToken) { + if (_Cts == null) + return Task.CompletedTask; leases.Dispose(); _Cts.Cancel(); var waitingPendingInvoices = _WaitingInvoices ?? Task.CompletedTask;