From fd068695effae7a965b4417b1af6cffa0689b644 Mon Sep 17 00:00:00 2001 From: chris meyers Date: Fri, 17 Apr 2020 13:16:11 -0400 Subject: [PATCH] cleanup group membership on disconnect * zcard asgi::group:jobs-status_changed <-- to see a group set that continues to grow. Issue this command in a loop while refreshing the browser page on the jobs list. Before this change the set size would continue to grow as daphne channel names are added to the group. After this change the set size stays stable at the expected, 1. --- awx/main/consumers.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/awx/main/consumers.py b/awx/main/consumers.py index d9edbc5ad1..5966a57f57 100644 --- a/awx/main/consumers.py +++ b/awx/main/consumers.py @@ -108,6 +108,7 @@ class BroadcastConsumer(AsyncJsonWebsocketConsumer): async def disconnect(self, code): # TODO: log ip of disconnected client logger.info("Client disconnected") + await self.channel_layer.group_discard(settings.BROADCAST_WEBSOCKET_GROUP_NAME, self.channel_name) async def internal_message(self, event): await self.send(event['text']) @@ -132,6 +133,14 @@ class EventConsumer(AsyncJsonWebsocketConsumer): await self.send_json({"close": True}) await self.close() + async def disconnect(self, code): + current_groups = set(self.scope['session'].pop('groups') if 'groups' in self.scope['session'] else []) + for group_name in current_groups: + await self.channel_layer.group_discard( + group_name, + self.channel_name, + ) + @database_sync_to_async def user_can_see_object_id(self, user_access, oid): # At this point user is a channels.auth.UserLazyObject object