diff --git a/tests/client_tests/integration/test_reconnect.py b/tests/client_tests/integration/test_reconnect.py index 1bebdc9d3..690ad2690 100644 --- a/tests/client_tests/integration/test_reconnect.py +++ b/tests/client_tests/integration/test_reconnect.py @@ -64,6 +64,7 @@ class ReconnectTests(IntegrationTestCase): self.ledger.config['connect_timeout'] = 30 network = BaseNetwork(self.ledger) + self.addCleanup(network.stop) asyncio.ensure_future(network.start()) await asyncio.wait_for(network.on_connected.first, timeout=1) self.assertTrue(network.is_connected) diff --git a/torba/client/basedatabase.py b/torba/client/basedatabase.py index 7c8e05606..b496c7e88 100644 --- a/torba/client/basedatabase.py +++ b/torba/client/basedatabase.py @@ -31,6 +31,8 @@ class AIOSQLite: self.executor.submit(conn.close) self.executor.shutdown(wait=True) conn = self.connection + if not conn: + return self.connection = None return asyncio.get_event_loop_policy().get_event_loop().call_later(0.01, __close, conn) diff --git a/torba/client/basenetwork.py b/torba/client/basenetwork.py index 692b6b312..35e82974d 100644 --- a/torba/client/basenetwork.py +++ b/torba/client/basenetwork.py @@ -82,7 +82,8 @@ class BaseNetwork: await client.send_request('server.banner') return client except (asyncio.TimeoutError, asyncio.CancelledError) as error: - client.connection_lost(error) + if not client.is_closing(): + client.abort() raise error futures = [] for server in self.config['default_servers']: