Skip to content

Commit

Permalink
Fixing problem with infinite connecting threads
Browse files Browse the repository at this point in the history
Whenever the internet connection is lost, the handle_reconnect function initiates a new thread for reconnection each time. As a result, multiple threads may attempt to reconnect simultaneously.
  • Loading branch information
SipanOhanyan authored Nov 12, 2024
1 parent bc4ade2 commit 6742654
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions signalrcore/transport/websockets/websocket_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,15 @@ def handle_reconnect(self):
except Exception as ex:
self.logger.error(ex)
sleep_time = self.reconnection_handler.next()
threading.Thread(
target=self.deferred_reconnect,
args=(sleep_time,)
).start()
self.deferred_reconnect(sleep_time)

def deferred_reconnect(self, sleep_time):
time.sleep(sleep_time)
try:
if not self.connection_alive:
self.send(PingMessage())
if not self.connection_checker.running:
self.send(PingMessage())
except Exception as ex:
self.logger.error(ex)
self.reconnection_handler.reconnecting = False
self.connection_alive = False
self.connection_alive = False

0 comments on commit 6742654

Please sign in to comment.