stuck in retrying backend loop, fix issue #652 (#862)

* maybe solution to issue #652

* formatting, when precommit merge?

* Update lnbits/app.py

* Update lnbits/app.py

Co-authored-by: dni <dni.khr@gmail.com>
Co-authored-by: calle <93376500+callebtc@users.noreply.github.com>
This commit is contained in:
dni ⚡ 2022-08-13 14:46:47 +02:00 committed by GitHub
parent 28661903b6
commit 034813a1ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
import asyncio
import importlib
import logging
import signal
import sys
import traceback
import warnings
@ -101,16 +102,27 @@ def create_app(config_object="lnbits.settings") -> FastAPI:
def check_funding_source(app: FastAPI) -> None:
@app.on_event("startup")
async def check_wallet_status():
original_sigint_handler = signal.getsignal(signal.SIGINT)
def signal_handler(signal, frame):
logger.debug(f"SIGINT received, terminating LNbits.")
sys.exit(1)
signal.signal(signal.SIGINT, signal_handler)
while True:
error_message, balance = await WALLET.status()
if not error_message:
break
logger.error(
f"The backend for {WALLET.__class__.__name__} isn't working properly: '{error_message}'",
RuntimeWarning,
)
logger.info("Retrying connection to backend in 5 seconds...")
await asyncio.sleep(5)
try:
error_message, balance = await WALLET.status()
if not error_message:
break
logger.error(
f"The backend for {WALLET.__class__.__name__} isn't working properly: '{error_message}'",
RuntimeWarning,
)
logger.info("Retrying connection to backend in 5 seconds...")
await asyncio.sleep(5)
except:
pass
signal.signal(signal.SIGINT, original_sigint_handler)
logger.info(
f"✔️ Backend {WALLET.__class__.__name__} connected and with a balance of {balance} msat."
)