From 5f41003fb111791d54170a2e20e6f3aef91d2251 Mon Sep 17 00:00:00 2001 From: Rick Elrod Date: Sat, 10 Dec 2022 02:40:48 -0600 Subject: [PATCH] Prevent looping issue when task/web share a Redis Signed-off-by: Rick Elrod --- awx/main/consumers.py | 2 +- awx/main/wsrelay.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/awx/main/consumers.py b/awx/main/consumers.py index d830c03a52..e2d47a96fb 100644 --- a/awx/main/consumers.py +++ b/awx/main/consumers.py @@ -240,6 +240,6 @@ def emit_channel_notification(group, payload): run_sync( channel_layer.group_send( group, - {"type": "internal.message", "text": payload_dumped}, + {"type": "internal.message", "text": payload_dumped, "needs_relay": True}, ) ) diff --git a/awx/main/wsrelay.py b/awx/main/wsrelay.py index a1abc3ec3d..e935850514 100644 --- a/awx/main/wsrelay.py +++ b/awx/main/wsrelay.py @@ -164,6 +164,14 @@ class WebsocketRelayConnection: while True: try: msg = await asyncio.wait_for(self.channel_layer.receive(consumer_channel), timeout=10) + if not msg.get("needs_relay"): + # This is added in by emit_channel_notification(). It prevents us from looping + # in the event that we are sharing a redis with a web instance. We'll see the + # message once (it'll have needs_relay=True), we'll delete that, and then forward + # the message along. The web instance will add it back to the same channels group, + # but it won't have needs_relay=True, so we'll ignore it. + continue + del msg["needs_relay"] except asyncio.TimeoutError: current_subscriptions = self.producers[name]["subscriptions"] if len(current_subscriptions) == 0: