Skip to content

Commit

Permalink
Fix stale websockets, breaking connector.stop()
Browse files Browse the repository at this point in the history
+ fixes (sousa-andre#18)
+ Each WebSocket registered by the user is now stored in a list called self.connections. This allows us to iterate over each stored connection object later when the connector.stop() method is called. By unregistering each connection, the method can successfully close the connections as intended. This prevents the occurrence of an infinite loop, which could happen if the @connector.ws.register() decorator was used to register a connection before
  • Loading branch information
Avnsx authored Jul 16, 2023
1 parent 768d79b commit ee3f4d3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lcu_driver/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ class Connector(BaseConnector):
def __init__(self, *, loop=None):
super().__init__(loop)
self._repeat_flag = True
self.connections = []
self.connection = None

def register_connection(self, connection):
self.connections.append(self)
self.connection = connection

def unregister_connection(self, _):
self.connections.remove(self)
self.connection = None

@property
Expand Down Expand Up @@ -78,6 +81,11 @@ async def stop(self) -> None:
:rtype: None
"""
self._repeat_flag = False

# close user-registered connections first, so listening to stale websockets won't cause an infinite loop
for e in self.connections:
self.unregister_connection(e)

if self.connection is not None:
await self.connection._close()

Expand Down

0 comments on commit ee3f4d3

Please sign in to comment.