diff --git a/src/socketio/async_client.py b/src/socketio/async_client.py index 69832d4..f33e9ab 100644 --- a/src/socketio/async_client.py +++ b/src/socketio/async_client.py @@ -188,9 +188,10 @@ class AsyncClient(base_client.BaseClient): while True: await self.eio.wait() await self.sleep(1) # give the reconnect task time to start up - if self.eio.state == 'connected': # connected during await self.sleep(1) - continue if not self._reconnect_task: + if self.eio.state == 'connected': # pragma: no cover + # connected while sleeping above + continue break await self._reconnect_task if self.eio.state != 'connected': diff --git a/src/socketio/client.py b/src/socketio/client.py index 68bcdda..374efd4 100644 --- a/src/socketio/client.py +++ b/src/socketio/client.py @@ -179,10 +179,13 @@ class Client(base_client.BaseClient): while True: self.eio.wait() self.sleep(1) # give the reconnect task time to start up - if self.eio.state != 'connected': # reconnect task finished while `self.sleep(1)` was executing - continue if not self._reconnect_task: - break + if self.eio.state == 'connected': # pragma: no cover + # connected while sleeping above + continue + else: + # the reconnect task gave up + break self._reconnect_task.join() if self.eio.state != 'connected': break