add hub_timeout and propagate it to network code

This commit is contained in:
Victor Shyba 2021-03-13 02:31:03 -03:00
parent fea893d76c
commit 91323a21cf
6 changed files with 15 additions and 0 deletions

View file

@ -628,6 +628,7 @@ class Config(CLIConfig):
# protocol timeouts # protocol timeouts
download_timeout = Float("Cumulative timeout for a stream to begin downloading before giving up", 30.0) 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) 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) 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) node_rpc_timeout = Float("Timeout when making a DHT request", constants.RPC_TIMEOUT)

BIN
lbry/wallet/__init__.pyc Normal file

Binary file not shown.

View file

@ -183,6 +183,7 @@ class WalletManager:
ledger_config = { ledger_config = {
'auto_connect': True, 'auto_connect': True,
'explicit_servers': [], 'explicit_servers': [],
'hub_timeout': config.hub_timeout,
'default_servers': config.lbryum_servers, 'default_servers': config.lbryum_servers,
'known_hubs': config.known_hubs, 'known_hubs': config.known_hubs,
'jurisdiction': config.jurisdiction, 'jurisdiction': config.jurisdiction,
@ -236,6 +237,7 @@ class WalletManager:
'default_servers': Config.lbryum_servers.default, 'default_servers': Config.lbryum_servers.default,
'known_hubs': self.config.known_hubs, 'known_hubs': self.config.known_hubs,
'jurisdiction': self.config.jurisdiction, 'jurisdiction': self.config.jurisdiction,
'hub_timeout': self.config.hub_timeout,
'data_path': self.config.wallet_dir, 'data_path': self.config.wallet_dir,
} }
if Config.lbryum_servers.is_set(self.config): if Config.lbryum_servers.is_set(self.config):

View file

@ -294,6 +294,7 @@ class Network:
(pong.country_name != self.jurisdiction): (pong.country_name != self.jurisdiction):
continue continue
client = ClientSession(network=self, server=(host, port)) client = ClientSession(network=self, server=(host, port))
client = ClientSession(network=self, server=(host, port), timeout=self.config['hub_timeout'])
try: try:
await client.create_connection() await client.create_connection()
log.warning("Connected to spv server %s:%i", host, port) log.warning("Connected to spv server %s:%i", host, port)

View file

@ -136,6 +136,7 @@ class WalletNode:
'default_servers': Config.lbryum_servers.default, 'default_servers': Config.lbryum_servers.default,
'data_path': self.data_path, 'data_path': self.data_path,
'known_hubs': config.known_hubs if config else KnownHubsList() 'known_hubs': config.known_hubs if config else KnownHubsList()
'hub_timeout': 30,
} }
}, },
'wallets': [wallet_file_name] 'wallets': [wallet_file_name]

View file

@ -9,6 +9,7 @@ from lbry.wallet.orchstr8.node import SPVNode
from lbry.wallet.rpc import RPCSession from lbry.wallet.rpc import RPCSession
from lbry.wallet.server.udp import StatusServer from lbry.wallet.server.udp import StatusServer
from lbry.testcase import IntegrationTestCase, AsyncioTestCase from lbry.testcase import IntegrationTestCase, AsyncioTestCase
from lbry.conf import Config
class NetworkTests(IntegrationTestCase): class NetworkTests(IntegrationTestCase):
@ -138,6 +139,15 @@ class ReconnectTests(IntegrationTestCase):
await self.ledger.network.on_connected.first await self.ledger.network.on_connected.first
self.assertTrue(self.ledger.network.is_connected) 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): # async def test_online_but_still_unavailable(self):
# # Edge case. See issue #2445 for context # # Edge case. See issue #2445 for context
# self.assertIsNotNone(self.ledger.network.session_pool.fastest_session) # self.assertIsNotNone(self.ledger.network.session_pool.fastest_session)