From b6ee33e56cf2679664c1b894bf7e5d33a30976db Mon Sep 17 00:00:00 2001 From: humayunsr Date: Sat, 14 Dec 2024 15:42:51 +0500 Subject: [PATCH] Prevent multiple tasks for reconnection (#1369) * Prevent multiple taks for reconnection As discussed here. https://github.com/miguelgrinberg/python-socketio/discussions/1367 In certain scenarios, this library creates multiple reconnection tasks. A check is added to make sure that reconnection task starts only when this task is not running. Signed-off-by: Humayun Ajmal * async client --------- Signed-off-by: Humayun Ajmal Co-authored-by: Miguel Grinberg --- src/socketio/async_client.py | 2 +- src/socketio/client.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/socketio/async_client.py b/src/socketio/async_client.py index 0d85aa1..fb1abc1 100644 --- a/src/socketio/async_client.py +++ b/src/socketio/async_client.py @@ -581,7 +581,7 @@ class AsyncClient(base_client.BaseClient): self.callbacks = {} self._binary_packet = None self.sid = None - if will_reconnect: + if will_reconnect and not self._reconnect_task: self._reconnect_task = self.start_background_task( self._handle_reconnect) diff --git a/src/socketio/client.py b/src/socketio/client.py index 00d7961..c4f9eaa 100644 --- a/src/socketio/client.py +++ b/src/socketio/client.py @@ -539,7 +539,7 @@ class Client(base_client.BaseClient): self.callbacks = {} self._binary_packet = None self.sid = None - if will_reconnect: + if will_reconnect and not self._reconnect_task: self._reconnect_task = self.start_background_task( self._handle_reconnect)