From 7500b1fbee57cd34bcdaaec7846e88a97cc8b829 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Fri, 7 Sep 2018 20:26:45 +0200 Subject: [PATCH] detect lost connection supersedes #4697 --- electrum/interface.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/electrum/interface.py b/electrum/interface.py index 0c1515eae..21e165e18 100644 --- a/electrum/interface.py +++ b/electrum/interface.py @@ -68,7 +68,7 @@ class NotificationSession(ClientSession): assert False, request.method - +# FIXME this is often raised inside a TaskGroup, but then it's not silent :( class GracefulDisconnect(AIOSafeSilentException): pass @@ -238,8 +238,15 @@ class Interface(PrintError): async with self.group as group: await group.spawn(self.run_fetch_blocks(subscription_res, copy_header_queue)) await group.spawn(self.subscribe_to_headers(header_queue, copy_header_queue)) + await group.spawn(self.monitor_connection()) # NOTE: group.__aexit__ will be called here; this is needed to notice exceptions in the group! + async def monitor_connection(self): + while True: + await asyncio.sleep(1) + if not self.session or self.session.is_closing(): + raise GracefulDisconnect('server closed session') + async def subscribe_to_headers(self, header_queue, copy_header_queue): while True: try: