From 73cb3dc4ee75cca9d371acfa7bedb34889b56373 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Mon, 9 Jul 2018 01:08:09 +0900 Subject: [PATCH] Fix listen loop for LND --- .../Lightning/Lnd/LndInvoiceClient.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/BTCPayServer/Payments/Lightning/Lnd/LndInvoiceClient.cs b/BTCPayServer/Payments/Lightning/Lnd/LndInvoiceClient.cs index 1a931d98b..ae222a231 100644 --- a/BTCPayServer/Payments/Lightning/Lnd/LndInvoiceClient.cs +++ b/BTCPayServer/Payments/Lightning/Lnd/LndInvoiceClient.cs @@ -38,19 +38,19 @@ namespace BTCPayServer.Payments.Lightning.Lnd urlBuilder.Append(_Parent.BaseUrl).Append("/v1/invoices/subscribe"); try { - while (!_Cts.IsCancellationRequested) + using (var client = _Parent.CreateHttpClient()) { - using (var client = _Parent.CreateHttpClient()) + client.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite); + + var request = new HttpRequestMessage(HttpMethod.Get, urlBuilder.ToString()); + + using (var response = await client.SendAsync( + request, HttpCompletionOption.ResponseHeadersRead, _Cts.Token)) { - client.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite); - - var request = new HttpRequestMessage(HttpMethod.Get, urlBuilder.ToString()); - - using (var response = await client.SendAsync( - request, HttpCompletionOption.ResponseHeadersRead, _Cts.Token)) + using (var body = await response.Content.ReadAsStreamAsync()) + using (var reader = new StreamReader(body)) { - using (var body = await response.Content.ReadAsStreamAsync()) - using (var reader = new StreamReader(body)) + while (!_Cts.IsCancellationRequested) { string line = await reader.ReadLineAsync().WithCancellation(_Cts.Token); if (line != null && line.StartsWith("{\"result\":", StringComparison.OrdinalIgnoreCase))