From b56dbd19f96dd59e54c89be0f38295060e3ba9de Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Mon, 8 Aug 2022 10:35:26 -0400 Subject: [PATCH 1/4] --exit-on-disconnect flag to start lbrynet --- lbry/conf.py | 3 +++ lbry/wallet/manager.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lbry/conf.py b/lbry/conf.py index d2dc8bb3ae..67e2b416d3 100644 --- a/lbry/conf.py +++ b/lbry/conf.py @@ -574,6 +574,9 @@ class TranscodeConfig(BaseConfig): class CLIConfig(TranscodeConfig): api = String('Host name and port for lbrynet daemon API.', 'localhost:5279', metavar='HOST:PORT') + exit_on_disconnect = Toggle( + 'Shutdown daemon when connection to wallet server closes.', False + ) @property def api_connection_url(self) -> str: diff --git a/lbry/wallet/manager.py b/lbry/wallet/manager.py index 911adcf879..557c62a3e8 100644 --- a/lbry/wallet/manager.py +++ b/lbry/wallet/manager.py @@ -190,7 +190,8 @@ async def from_lbrynet_config(cls, config: Config): 'jurisdiction': config.jurisdiction, 'concurrent_hub_requests': config.concurrent_hub_requests, 'data_path': config.wallet_dir, - 'tx_cache_size': config.transaction_cache_size + 'tx_cache_size': config.transaction_cache_size, + 'exit_on_disconnect': config.exit_on_disconnect, } if 'LBRY_FEE_PER_NAME_CHAR' in os.environ: ledger_config['fee_per_name_char'] = int(os.environ.get('LBRY_FEE_PER_NAME_CHAR')) @@ -244,6 +245,7 @@ async def reset(self): 'hub_timeout': self.config.hub_timeout, 'concurrent_hub_requests': self.config.concurrent_hub_requests, 'data_path': self.config.wallet_dir, + 'exit_on_disconnect': self.config.exit_on_disconnect, } if Config.lbryum_servers.is_set(self.config): self.ledger.config['explicit_servers'] = self.config.lbryum_servers From f2777a713847ddbbbe461f10d0961e4caebc0d92 Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Thu, 11 Aug 2022 10:20:58 -0400 Subject: [PATCH 2/4] revert version --- lbry/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lbry/__init__.py b/lbry/__init__.py index df7d15ec08..2c5e1548ee 100644 --- a/lbry/__init__.py +++ b/lbry/__init__.py @@ -1,2 +1,2 @@ -__version__ = "0.110.0" +__version__ = "0.109.0" version = tuple(map(int, __version__.split('.'))) # pylint: disable=invalid-name From 888bd854703ac79a2ea65cbd56b2ef2f7d141af7 Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Thu, 11 Aug 2022 10:58:16 -0400 Subject: [PATCH 3/4] v0.110.0 --- lbry/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lbry/__init__.py b/lbry/__init__.py index 2c5e1548ee..df7d15ec08 100644 --- a/lbry/__init__.py +++ b/lbry/__init__.py @@ -1,2 +1,2 @@ -__version__ = "0.109.0" +__version__ = "0.110.0" version = tuple(map(int, __version__.split('.'))) # pylint: disable=invalid-name From 8bd7008fdc23fcc606994fc82871fe2954eda63f Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Mon, 29 Aug 2022 10:51:28 -0400 Subject: [PATCH 4/4] actually exit on disconnect --- lbry/wallet/network.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lbry/wallet/network.py b/lbry/wallet/network.py index 55b8b145b3..484b98c931 100644 --- a/lbry/wallet/network.py +++ b/lbry/wallet/network.py @@ -3,6 +3,7 @@ import json import socket import random +import sys from time import perf_counter from collections import defaultdict from typing import Dict, Optional, Tuple @@ -197,6 +198,10 @@ def known_hubs(self): def jurisdiction(self): return self.config.get("jurisdiction") + @property + def exit_on_disconnect(self): + return self.config["exit_on_disconnect"] + def disconnect(self): if self._keepalive_task and not self._keepalive_task.done(): self._keepalive_task.cancel() @@ -373,7 +378,13 @@ def is_connected(self): def rpc(self, list_or_method, args, restricted=True, session: Optional[ClientSession] = None): if session or self.is_connected: session = session or self.client - return session.send_request(list_or_method, args) + try: + return session.send_request(list_or_method, args) + except asyncio.TimeoutError: + if self.exit_on_disconnect: + log.error("exiting on server disconnect") + sys.exit(1) + raise else: self._urgent_need_reconnect.set() raise ConnectionError("Attempting to send rpc request when connection is not available.") @@ -387,9 +398,16 @@ async def retriable_call(self, function, *args, **kwargs): try: return await function(*args, **kwargs) except asyncio.TimeoutError: - log.warning("Wallet server call timed out, retrying.") + if self.exit_on_disconnect: + log.error("Wallet server call timed out, exiting on server disconnect.") + sys.exit(1) + else: + log.warning("Wallet server call timed out, retrying.") except ConnectionError: log.warning("connection error") + if self.exit_on_disconnect: + log.error("exiting on server disconnect") + sys.exit(1) raise asyncio.CancelledError() # if we got here, we are shutting down def _update_remote_height(self, header_args):