diff --git a/BTCPayServer/Controllers/NotificationsController.cs b/BTCPayServer/Controllers/NotificationsController.cs index e8a1f0b59..40e697327 100644 --- a/BTCPayServer/Controllers/NotificationsController.cs +++ b/BTCPayServer/Controllers/NotificationsController.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Net.WebSockets; using System.Threading; using System.Threading.Tasks; using BTCPayServer.Abstractions.Constants; @@ -69,14 +70,15 @@ namespace BTCPayServer.Controllers } }); - while (!cancellationToken.IsCancellationRequested) - { - await Task.Delay(2000, cancellationToken); - } + await websocketHelper.NextMessageAsync(cancellationToken); } catch (TaskCanceledException) { // ignored + } + catch (WebSocketException) + { + } finally { diff --git a/BTCPayServer/WebsocketExtensions.cs b/BTCPayServer/WebsocketExtensions.cs index 849fe4d2b..75547fd63 100644 --- a/BTCPayServer/WebsocketExtensions.cs +++ b/BTCPayServer/WebsocketExtensions.cs @@ -23,10 +23,10 @@ wait: if (completed == waiting) { await webSocket.SendAsync(Encoding.UTF8.GetBytes("ping"), WebSocketMessageType.Text, true, cancellationToken); - waiting = Task.Delay(TimeSpan.FromSeconds(30), cancellationToken); + waiting = Task.Delay(TimeSpan.FromSeconds(25), cancellationToken); goto wait; } - return receiving.Result; + return await receiving; } } }