diff --git a/torba/torba/client/basenetwork.py b/torba/torba/client/basenetwork.py index 466573d57..58a51eef3 100644 --- a/torba/torba/client/basenetwork.py +++ b/torba/torba/client/basenetwork.py @@ -80,9 +80,9 @@ class ClientSession(BaseClientSession): await asyncio.wait_for(self.trigger_urgent_reconnect.wait(), timeout=retry_delay) except asyncio.TimeoutError: pass - except asyncio.CancelledError as exception: - self.connection_lost(exception) - raise exception + except asyncio.CancelledError: + self.synchronous_close() + raise finally: self.trigger_urgent_reconnect.clear() diff --git a/torba/torba/rpc/session.py b/torba/torba/rpc/session.py index 9ff3e7ed0..7b0350b15 100644 --- a/torba/torba/rpc/session.py +++ b/torba/torba/rpc/session.py @@ -254,6 +254,7 @@ class SessionBase(asyncio.Protocol): if self.transport: self.transport.abort() + # TODO: replace with synchronous_close async def close(self, *, force_after=30): """Close the connection and return when closed.""" self._close() @@ -263,6 +264,11 @@ class SessionBase(asyncio.Protocol): self.abort() await self._pm_task + def synchronous_close(self): + self._close() + if self._pm_task and not self._pm_task.done(): + self._pm_task.cancel() + class MessageSession(SessionBase): """Session class for protocols where messages are not tied to responses,