Skip to content

Commit 119f4ee

Browse files
committed
Fix: Gracefully handle exceptions in PubSub message retrieval
An exception was observed in the logs when retrieving messages from the Redis subscription. This change adds a try-except block to catch potential exceptions during the `get_message` call and handle them gracefully by returning None. This prevents the subscription loop from crashing and improves the overall stability of the PubSub system. Signed-off-by: Denys Fedoryshchenko <[email protected]>
1 parent 24066ca commit 119f4ee

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

api/pubsub.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,14 @@ async def listen(self, sub_id, user=None):
135135
f"not owned by {user}")
136136
while True:
137137
self._subscriptions[sub_id]['last_poll'] = datetime.utcnow()
138-
msg = await sub['redis_sub'].get_message(
139-
ignore_subscribe_messages=True, timeout=1.0
140-
)
138+
msg = None
139+
try:
140+
msg = await sub['redis_sub'].get_message(
141+
ignore_subscribe_messages=True, timeout=1.0
142+
)
143+
except Exception as e:
144+
return None # Handle any exceptions gracefully
145+
141146
if msg is None:
142147
continue
143148
msg_data = json.loads(msg['data'])

0 commit comments

Comments
 (0)