diff --git a/lbry/conf.py b/lbry/conf.py index 7a4abd080..ed6295780 100644 --- a/lbry/conf.py +++ b/lbry/conf.py @@ -544,6 +544,7 @@ class Config(CLIConfig): # protocol timeouts download_timeout = Float("Cumulative timeout for a stream to begin downloading before giving up", 30.0) blob_download_timeout = Float("Timeout to download a blob from a peer", 30.0) + hub_timeout = Float("Timeout when making a hub request", 30.0) peer_connect_timeout = Float("Timeout to establish a TCP connection to a peer", 3.0) node_rpc_timeout = Float("Timeout when making a DHT request", constants.RPC_TIMEOUT) diff --git a/lbry/wallet/manager.py b/lbry/wallet/manager.py index bff251a06..7b06f5f95 100644 --- a/lbry/wallet/manager.py +++ b/lbry/wallet/manager.py @@ -182,6 +182,7 @@ class WalletManager: ledger_config = { 'auto_connect': True, + 'hub_timeout': config.hub_timeout, 'default_servers': config.lbryum_servers, 'data_path': config.wallet_dir, 'tx_cache_size': config.transaction_cache_size @@ -226,6 +227,7 @@ class WalletManager: self.ledger.config = { 'auto_connect': True, 'default_servers': self.config.lbryum_servers, + 'hub_timeout': self.config.hub_timeout, 'data_path': self.config.wallet_dir, } await self.ledger.stop() diff --git a/lbry/wallet/network.py b/lbry/wallet/network.py index 99dad77b0..7dc3319d2 100644 --- a/lbry/wallet/network.py +++ b/lbry/wallet/network.py @@ -263,7 +263,7 @@ class Network: async def connect_to_fastest(self) -> Optional[ClientSession]: fastest_spvs = await self.get_n_fastest_spvs() for (host, port) in fastest_spvs: - client = ClientSession(network=self, server=(host, port)) + client = ClientSession(network=self, server=(host, port), timeout=self.config['hub_timeout']) try: await client.create_connection() log.warning("Connected to spv server %s:%i", host, port) diff --git a/lbry/wallet/orchstr8/node.py b/lbry/wallet/orchstr8/node.py index be4a4fc7a..252da873c 100644 --- a/lbry/wallet/orchstr8/node.py +++ b/lbry/wallet/orchstr8/node.py @@ -131,7 +131,8 @@ class WalletNode: self.ledger_class.get_id(): { 'api_port': self.port, 'default_servers': [(spv_node.hostname, spv_node.port)], - 'data_path': self.data_path + 'data_path': self.data_path, + 'hub_timeout': 30, } }, 'wallets': [wallet_file_name] diff --git a/tests/integration/blockchain/test_network.py b/tests/integration/blockchain/test_network.py index 60ca442a0..4f89930fd 100644 --- a/tests/integration/blockchain/test_network.py +++ b/tests/integration/blockchain/test_network.py @@ -9,6 +9,7 @@ from lbry.wallet.orchstr8.node import SPVNode from lbry.wallet.rpc import RPCSession from lbry.wallet.server.udp import StatusServer from lbry.testcase import IntegrationTestCase, AsyncioTestCase +from lbry.conf import Config class NetworkTests(IntegrationTestCase): @@ -138,6 +139,15 @@ class ReconnectTests(IntegrationTestCase): await self.ledger.network.on_connected.first self.assertTrue(self.ledger.network.is_connected) + async def test_timeout_propagated_from_config(self): + conf = Config() + self.assertEqual(self.ledger.network.client.timeout, 30) + conf.hub_timeout = 123.0 + conf.lbryum_servers = self.ledger.config['default_servers'] + self.manager.config = conf + await self.manager.reset() + self.assertEqual(self.ledger.network.client.timeout, 123) + # async def test_online_but_still_unavailable(self): # # Edge case. See issue #2445 for context # self.assertIsNotNone(self.ledger.network.session_pool.fastest_session)