Skip to content

Commit

Permalink
Fixing wsrelay connection loop (#14692)
Browse files Browse the repository at this point in the history
* Fixing wsrelay connection loop

* The loop was being interrupted when reaching the return statements, causing a race condition that would make nodes remain disconnected from their websockets
* Added log messages for the previous return state to improve the logging from this state.

* Added logging for malformed payload

* Update awx/main/wsrelay.py

Co-authored-by: Rick Elrod <rick@elrod.me>

* Moved logmsg outside condition

---------

Co-authored-by: Lucas Benedito <lbenedit@redhat.com>
Co-authored-by: Rick Elrod <rick@elrod.me>
  • Loading branch information
3 people authored Dec 4, 2023
1 parent 478e2cb commit fb04e5d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions awx/main/wsrelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,21 +227,24 @@ async def on_ws_heartbeat(self, conn):
continue
try:
if not notif.payload or notif.channel != "web_ws_heartbeat":
return
logger.warning(f"Unexpected channel or missing payload. {notif.channel}, {notif.payload}")
continue

try:
payload = json.loads(notif.payload)
except json.JSONDecodeError:
logmsg = "Failed to decode message from pg_notify channel `web_ws_heartbeat`"
if logger.isEnabledFor(logging.DEBUG):
logmsg = "{} {}".format(logmsg, payload)
logger.warning(logmsg)
return
logger.warning(logmsg)
continue

# Skip if the message comes from the same host we are running on
# In this case, we'll be sharing a redis, no need to relay.
if payload.get("hostname") == self.local_hostname:
return
hostname = payload.get("hostname")
logger.debug("Received a heartbeat request for {hostname}. Skipping as we use redis for local host.")
continue

action = payload.get("action")

Expand All @@ -250,7 +253,7 @@ async def on_ws_heartbeat(self, conn):
ip = payload.get("ip") or hostname # try back to hostname if ip isn't supplied
if ip is None:
logger.warning(f"Received invalid {action} ws_heartbeat, missing hostname and ip: {payload}")
return
continue
logger.debug(f"Web host {hostname} ({ip}) {action} heartbeat received.")

if action == "online":
Expand Down

0 comments on commit fb04e5d

Please sign in to comment.