mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-01 17:55:20 +00:00
network.best_effort_reliable: force DC if req times out; retry on new iface
This commit is contained in:
parent
4984890265
commit
3e2c5e8656
2 changed files with 19 additions and 9 deletions
|
@ -130,7 +130,6 @@ def serialize_server(host: str, port: Union[str, int], protocol: str) -> str:
|
||||||
class Interface(PrintError):
|
class Interface(PrintError):
|
||||||
|
|
||||||
def __init__(self, network, server, config_path, proxy):
|
def __init__(self, network, server, config_path, proxy):
|
||||||
self.exception = None
|
|
||||||
self.ready = asyncio.Future()
|
self.ready = asyncio.Future()
|
||||||
self.got_disconnected = asyncio.Future()
|
self.got_disconnected = asyncio.Future()
|
||||||
self.server = server
|
self.server = server
|
||||||
|
|
|
@ -642,17 +642,28 @@ class Network(PrintError):
|
||||||
async def make_reliable_wrapper(self, *args, **kwargs):
|
async def make_reliable_wrapper(self, *args, **kwargs):
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
iface = self.interface
|
iface = self.interface
|
||||||
session = iface.session if iface else None
|
# retry until there is a main interface
|
||||||
if not session:
|
if not iface:
|
||||||
# no main interface; try again
|
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
continue
|
continue # try again
|
||||||
|
# wait for it to be usable
|
||||||
|
iface_ready = iface.ready
|
||||||
|
iface_disconnected = iface.got_disconnected
|
||||||
|
await asyncio.wait([iface_ready, iface_disconnected], return_when=asyncio.FIRST_COMPLETED)
|
||||||
|
if not iface_ready.done() or iface_ready.cancelled():
|
||||||
|
await asyncio.sleep(0.1)
|
||||||
|
continue # try again
|
||||||
|
# try actual request
|
||||||
success_fut = asyncio.ensure_future(func(self, *args, **kwargs))
|
success_fut = asyncio.ensure_future(func(self, *args, **kwargs))
|
||||||
disconnected_fut = asyncio.shield(iface.got_disconnected)
|
await asyncio.wait([success_fut, iface_disconnected], return_when=asyncio.FIRST_COMPLETED)
|
||||||
await asyncio.wait([success_fut, disconnected_fut], return_when=asyncio.FIRST_COMPLETED)
|
if success_fut.done() and not success_fut.cancelled():
|
||||||
if success_fut.done():
|
|
||||||
if success_fut.exception():
|
if success_fut.exception():
|
||||||
raise success_fut.exception()
|
try:
|
||||||
|
raise success_fut.exception()
|
||||||
|
except RequestTimedOut:
|
||||||
|
await iface.close()
|
||||||
|
await iface_disconnected
|
||||||
|
continue # try again
|
||||||
return success_fut.result()
|
return success_fut.result()
|
||||||
# otherwise; try again
|
# otherwise; try again
|
||||||
raise Exception('no interface to do request on... gave up.')
|
raise Exception('no interface to do request on... gave up.')
|
||||||
|
|
Loading…
Add table
Reference in a new issue