Merge branch 'bug/websocket-clients' into 'dev'

Fix set size changed during iteration

See merge request crafty-controller/crafty-4!473
This commit is contained in:
Iain Powrie 2022-10-02 20:32:07 +00:00
commit a8fc02b3fe
2 changed files with 5 additions and 1 deletions

View File

@ -7,6 +7,7 @@
- Fix traceback on basic schedule with "days" interval ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/469))
- Fix bad method call with API stdin ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/470))<br>
*(Thank you ['IWant2Tryhard'](https://github.com/MyNameTsThad) for catching that 🐛)*
- Fix clients variable as static to prevent crash if client list changed while sending a websocket ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/473))
<br><br>
## --- [4.0.14] - 2022/09/23

View File

@ -85,7 +85,10 @@ class WebSocketHelper:
self.broadcast_with_fn(filter_fn, event_type, data)
def broadcast_with_fn(self, filter_fn, event_type: str, data):
clients = list(filter(filter_fn, self.clients))
# assign self.clients to a static variable here so hopefully
# the set size won't change
static_clients = self.clients
clients = list(filter(filter_fn, static_clients))
logger.debug(
f"Sending to {len(clients)} out of {len(self.clients)} "
f"clients: {json.dumps({'event': event_type, 'data': data})}"