Browse Source

Fixed bad event object used by asyncio client reconnect logic (Fixes #622)

pull/636/head
Miguel Grinberg 4 years ago
parent
commit
bff76c432c
No known key found for this signature in database GPG Key ID: 36848B262DF5F06C
  1. 3
      socketio/asyncio_client.py
  2. 4
      socketio/client.py
  3. 4
      tests/common/test_client.py

3
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)

4
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

4
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()

Loading…
Cancel
Save