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