From fbfab88257b53943d2c0ddeb697e0743b52b8d75 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Wed, 12 Jan 2022 00:10:55 +0900 Subject: [PATCH] Remove obsolete code in BitpayIPNSender --- .../HostedServices/BitpayIPNSender.cs | 70 ++----------------- 1 file changed, 5 insertions(+), 65 deletions(-) diff --git a/BTCPayServer/HostedServices/BitpayIPNSender.cs b/BTCPayServer/HostedServices/BitpayIPNSender.cs index 38e8f3c6b..5a980ca6d 100644 --- a/BTCPayServer/HostedServices/BitpayIPNSender.cs +++ b/BTCPayServer/HostedServices/BitpayIPNSender.cs @@ -151,7 +151,7 @@ namespace BTCPayServer.HostedServices var aggregatorEvent = new InvoiceIPNEvent(job.Notification.Data.Id, job.Notification.Event.Code, job.Notification.Event.Name); try { - HttpResponseMessage response = await SendNotification(job.Notification, cancellationToken); + using HttpResponseMessage response = await SendNotification(job.Notification, cancellationToken); reschedule = !response.IsSuccessStatusCode; aggregatorEvent.Error = reschedule ? $"Unexpected return code: {(int)response.StatusCode}" : null; _EventAggregator.Publish(aggregatorEvent); @@ -232,75 +232,15 @@ namespace BTCPayServer.HostedServices request.RequestUri = new Uri(notification.NotificationURL, UriKind.Absolute); request.Content = new StringContent(notificationString, UTF8, "application/json"); - var response = await Enqueue(notification.Data.Id, async () => - { - using (CancellationTokenSource cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken)) - { - cts.CancelAfter(TimeSpan.FromMinutes(1.0)); - return await _Client.SendAsync(request, cts.Token); - } - }); + + using CancellationTokenSource cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); + cts.CancelAfter(TimeSpan.FromMinutes(1.0)); + var response = await _Client.SendAsync(request, cts.Token); return response; } readonly Dictionary _SendingRequestsByInvoiceId = new Dictionary(); - - /// - /// Will make sure only one callback is called at once on the same invoiceId - /// - /// - /// - /// - private async Task Enqueue(string id, Func> sendRequest) - { - Task sending = null; - lock (_SendingRequestsByInvoiceId) - { - if (_SendingRequestsByInvoiceId.TryGetValue(id, out var executing)) - { - var completion = new TaskCompletionSource(); - sending = completion.Task; - _SendingRequestsByInvoiceId.Remove(id); - _SendingRequestsByInvoiceId.Add(id, sending); - executing.ContinueWith(_ => - { - sendRequest() - .ContinueWith(t => - { - if (t.Status == TaskStatus.RanToCompletion) - { - completion.TrySetResult(t.Result); - } - if (t.Status == TaskStatus.Faulted) - { - completion.TrySetException(t.Exception); - } - if (t.Status == TaskStatus.Canceled) - { - completion.TrySetCanceled(); - } - }, TaskScheduler.Default); - }, TaskScheduler.Default); - } - else - { - sending = sendRequest(); - _SendingRequestsByInvoiceId.Add(id, sending); - } - sending.ContinueWith(o => - { - lock (_SendingRequestsByInvoiceId) - { - _SendingRequestsByInvoiceId.TryGetValue(id, out var executing2); - if (executing2 == sending) - _SendingRequestsByInvoiceId.Remove(id); - } - }, TaskScheduler.Default); - } - return await sending; - } - readonly int MaxTry = 6; readonly CompositeDisposable leases = new CompositeDisposable();