From bba76140120df846415a61565eb0126be73c1e45 Mon Sep 17 00:00:00 2001 From: Riccardo Balbo Date: Tue, 14 Jan 2025 10:31:12 +0100 Subject: [PATCH] fix: Add timeout to wait_for_connection (#2885) --- lnbits/wallets/nwc.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lnbits/wallets/nwc.py b/lnbits/wallets/nwc.py index 828d5dbf..bbfad1ec 100644 --- a/lnbits/wallets/nwc.py +++ b/lnbits/wallets/nwc.py @@ -440,11 +440,14 @@ class NWCConnection: logger.error("Error closing subscription: " + str(e)) return subscription - async def _wait_for_connection(self): + async def _wait_for_connection(self, timeout: int = 60 * 2): """ Waits until the connection is ready """ + t = time.time() while not self.connected: + if time.time() - t > timeout: + raise Exception("Connection timeout, cannot connect to NWC service") if self._is_shutting_down(): raise Exception("Connection is closing") logger.debug("Waiting for connection...")