network: when switching servers, don't wait for old interface to close

The GUI blocks until network.set_parameters returns when switching servers,
which waits for switch_to_interface, which used to wait until interface.close()
returns. interface.close() tries to flush buffered writes to the wire, with a
30 sec timeout.

If the server or the network connection is slow, flushing the buffer can take
several seconds. In particular, servers running Fulcrum always seem to
timeout in this case, freezing the GUI for 30 seconds (when switching away).
This commit is contained in:
SomberNight
2020-12-13 18:08:36 +01:00
parent 91cdd12fa2
commit e83f0dd3fc
2 changed files with 11 additions and 5 deletions

View File

@@ -616,7 +616,8 @@ class Interface(Logger):
return conn, res['count']
def is_main_server(self) -> bool:
return self.network.default_server == self.server
return (self.network.interface == self or
self.network.interface is None and self.network.default_server == self.server)
async def open_session(self, sslc, exit_early=False):
session_factory = lambda *args, iface=self, **kwargs: NotificationSession(*args, **kwargs, interface=iface)
@@ -678,6 +679,9 @@ class Interface(Logger):
await asyncio.sleep(60)
async def close(self):
"""Closes the connection and waits for it to be closed.
We try to flush buffered data to the wire, so this can take some time.
"""
if self.session:
await self.session.close()
# monitor_connection will cancel tasks