From f4224a6766f0354a9dc4804bf23093cff4ebc1f0 Mon Sep 17 00:00:00 2001 From: Arseny <36441601+arkuzo@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:45:13 +0300 Subject: [PATCH 1/4] fix AsyncClient::wait unexpected return after success reconnect AsyncClient::wait use sleep(1) call to wait to start reconnect task. Sometimes reconnect is faster then 1 second, and wait returns while connection to server is established. Added one check to avoid this situation --- src/socketio/async_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/socketio/async_client.py b/src/socketio/async_client.py index e79fce0e..4869dfa0 100644 --- a/src/socketio/async_client.py +++ b/src/socketio/async_client.py @@ -188,7 +188,7 @@ async def wait(self): while True: await self.eio.wait() await self.sleep(1) # give the reconnect task time to start up - if not self._reconnect_task: + if not self._reconnect_task and self.eio.state != 'connected': break await self._reconnect_task if self.eio.state != 'connected': From 29256e50bb7c07f66101bc1c1518eb9a660e40d1 Mon Sep 17 00:00:00 2001 From: Arseny <36441601+arkuzo@users.noreply.github.com> Date: Tue, 19 Nov 2024 12:52:50 +0300 Subject: [PATCH 2/4] Making added check easier to understand in source code --- src/socketio/async_client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/socketio/async_client.py b/src/socketio/async_client.py index 4869dfa0..69832d42 100644 --- a/src/socketio/async_client.py +++ b/src/socketio/async_client.py @@ -188,7 +188,9 @@ async def wait(self): while True: await self.eio.wait() await self.sleep(1) # give the reconnect task time to start up - if not self._reconnect_task and self.eio.state != 'connected': + if self.eio.state == 'connected': # connected during await self.sleep(1) + continue + if not self._reconnect_task: break await self._reconnect_task if self.eio.state != 'connected': From 1663d4ac9373dee51d9512364c340ff22186fff4 Mon Sep 17 00:00:00 2001 From: Arseny <36441601+arkuzo@users.noreply.github.com> Date: Tue, 19 Nov 2024 15:14:01 +0300 Subject: [PATCH 3/4] fix Client::wait unexpected return after success reconnect --- src/socketio/client.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/socketio/client.py b/src/socketio/client.py index d7af4070..68bcdda7 100644 --- a/src/socketio/client.py +++ b/src/socketio/client.py @@ -179,6 +179,8 @@ def wait(self): 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 self._reconnect_task.join() From 9fad09f28f8a98c612c65ba16bffda026d9a2a18 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Sat, 14 Dec 2024 00:10:10 +0000 Subject: [PATCH 4/4] fixes --- src/socketio/async_client.py | 5 +++-- src/socketio/client.py | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/socketio/async_client.py b/src/socketio/async_client.py index 69832d42..f33e9ab9 100644 --- a/src/socketio/async_client.py +++ b/src/socketio/async_client.py @@ -188,9 +188,10 @@ async def wait(self): 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 68bcdda7..374efd45 100644 --- a/src/socketio/client.py +++ b/src/socketio/client.py @@ -179,10 +179,13 @@ def wait(self): 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