mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-02 10:15:20 +00:00
follow-up prev: make best_effort_reliable react faster to disconnects
This commit is contained in:
parent
6b8ad2d126
commit
4984890265
2 changed files with 11 additions and 8 deletions
|
@ -132,6 +132,7 @@ class Interface(PrintError):
|
|||
def __init__(self, network, server, config_path, proxy):
|
||||
self.exception = None
|
||||
self.ready = asyncio.Future()
|
||||
self.got_disconnected = asyncio.Future()
|
||||
self.server = server
|
||||
self.host, self.port, self.protocol = deserialize_server(self.server)
|
||||
self.port = int(self.port)
|
||||
|
@ -246,6 +247,7 @@ class Interface(PrintError):
|
|||
self.print_error("disconnecting gracefully. {}".format(e))
|
||||
finally:
|
||||
await self.network.connection_down(self.server)
|
||||
self.got_disconnected.set_result(1)
|
||||
return wrapper_func
|
||||
|
||||
@aiosafe
|
||||
|
|
|
@ -216,7 +216,7 @@ class Network(PrintError):
|
|||
# kick off the network. interface is the main server we are currently
|
||||
# communicating with. interfaces is the set of servers we are connecting
|
||||
# to or have an ongoing connection with
|
||||
self.interface = None
|
||||
self.interface = None # type: Interface
|
||||
self.interfaces = {}
|
||||
self.auto_connect = self.config.get('auto_connect', True)
|
||||
self.connecting = set()
|
||||
|
@ -647,13 +647,14 @@ class Network(PrintError):
|
|||
# no main interface; try again
|
||||
await asyncio.sleep(0.1)
|
||||
continue
|
||||
try:
|
||||
return await func(self, *args, **kwargs)
|
||||
except RequestTimedOut:
|
||||
if self.interface != iface:
|
||||
# main interface changed; try again
|
||||
continue
|
||||
raise
|
||||
success_fut = asyncio.ensure_future(func(self, *args, **kwargs))
|
||||
disconnected_fut = asyncio.shield(iface.got_disconnected)
|
||||
await asyncio.wait([success_fut, disconnected_fut], return_when=asyncio.FIRST_COMPLETED)
|
||||
if success_fut.done():
|
||||
if success_fut.exception():
|
||||
raise success_fut.exception()
|
||||
return success_fut.result()
|
||||
# otherwise; try again
|
||||
raise Exception('no interface to do request on... gave up.')
|
||||
return make_reliable_wrapper
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue