Skip to content

Commit

Permalink
fix AsyncClient::wait unexpected return after success reconnect (#1407)
Browse files Browse the repository at this point in the history
* 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

* Making added check easier to understand in source code

* fix Client::wait unexpected return after success reconnect

* fixes

---------

Co-authored-by: Miguel Grinberg <miguel.grinberg@gmail.com>
  • Loading branch information
arkuzo and miguelgrinberg authored Dec 14, 2024
1 parent db642bb commit 78d1124
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/socketio/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ async def wait(self):
await self.eio.wait()
await self.sleep(1) # give the reconnect task time to start up
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':
Expand Down
7 changes: 6 additions & 1 deletion src/socketio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,12 @@ def wait(self):
self.eio.wait()
self.sleep(1) # give the reconnect task time to start up
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
Expand Down

0 comments on commit 78d1124

Please sign in to comment.