diff --git a/socketio/asyncio_client.py b/socketio/asyncio_client.py index b2ad1ea..29f6e44 100644 --- a/socketio/asyncio_client.py +++ b/socketio/asyncio_client.py @@ -380,6 +380,8 @@ class AsyncClient(client.Client): event, *args) async def _handle_reconnect(self): + if self._reconnect_abort is None: # pragma: no cover + self._reconnect_abort = self.eio.create_event() self._reconnect_abort.clear() client.reconnecting_clients.append(self) attempt_count = 0 @@ -457,7 +459,6 @@ class AsyncClient(client.Client): async def _handle_eio_disconnect(self): """Handle the Engine.IO disconnection event.""" self.logger.info('Engine.IO connection dropped') - self._reconnect_abort.set() if self.connected: for n in self.namespaces: await self._trigger_event('disconnect', namespace=n) diff --git a/socketio/client.py b/socketio/client.py index d42d0d7..8eaa6ce 100644 --- a/socketio/client.py +++ b/socketio/client.py @@ -132,7 +132,7 @@ class Client(object): self.callbacks = {} self._binary_packet = None self._reconnect_task = None - self._reconnect_abort = self.eio.create_event() + self._reconnect_abort = None def is_asyncio_based(self): return False @@ -552,6 +552,8 @@ class Client(object): event, *args) def _handle_reconnect(self): + if self._reconnect_abort is None: # pragma: no cover + self._reconnect_abort = self.eio.create_event() self._reconnect_abort.clear() reconnecting_clients.append(self) attempt_count = 0 diff --git a/tests/common/test_client.py b/tests/common/test_client.py index 5c6ff2c..9f9481c 100644 --- a/tests/common/test_client.py +++ b/tests/common/test_client.py @@ -852,6 +852,7 @@ class TestClient(unittest.TestCase): def test_handle_reconnect(self, random): c = client.Client() c._reconnect_task = 'foo' + c._reconnect_abort = c.eio.create_event() c._reconnect_abort.wait = mock.MagicMock(return_value=False) c.connect = mock.MagicMock( side_effect=[ValueError, exceptions.ConnectionError, None] @@ -869,6 +870,7 @@ class TestClient(unittest.TestCase): def test_handle_reconnect_max_delay(self, random): c = client.Client(reconnection_delay_max=3) c._reconnect_task = 'foo' + c._reconnect_abort = c.eio.create_event() c._reconnect_abort.wait = mock.MagicMock(return_value=False) c.connect = mock.MagicMock( side_effect=[ValueError, exceptions.ConnectionError, None] @@ -886,6 +888,7 @@ class TestClient(unittest.TestCase): def test_handle_reconnect_max_attempts(self, random): c = client.Client(reconnection_attempts=2) c._reconnect_task = 'foo' + c._reconnect_abort = c.eio.create_event() c._reconnect_abort.wait = mock.MagicMock(return_value=False) c.connect = mock.MagicMock( side_effect=[ValueError, exceptions.ConnectionError, None] @@ -902,6 +905,7 @@ class TestClient(unittest.TestCase): def test_handle_reconnect_aborted(self, random): c = client.Client() c._reconnect_task = 'foo' + c._reconnect_abort = c.eio.create_event() c._reconnect_abort.wait = mock.MagicMock(side_effect=[False, True]) c.connect = mock.MagicMock(side_effect=exceptions.ConnectionError) c._handle_reconnect()