Keep webhook open when Matrix client disconnects #4

Open
opened 2024-12-31 15:05:56 +00:00 by ben · 0 comments
Owner

Currently, it seems that the webhook http server does not respond to queries while the Matrix client is not running with self.nio.sync_forever.

A way to replicate this

diff --git a/notflixbot/matrix.py b/notflixbot/matrix.py
index daa9b6d..4aef02e 100644
--- a/notflixbot/matrix.py
+++ b/notflixbot/matrix.py
@@ -115,7 +115,7 @@ class MatrixClient:
             try:
                 logger.info("Matrix client syncing forever")
                 return await self.nio.sync_forever(timeout=3000, full_state=True)
-            except (asyncio.exceptions.TimeoutError, aiohttp.client_exceptions.ClientOSError) as e:
+            except (KeyError, asyncio.exceptions.TimeoutError, aiohttp.client_exceptions.ClientOSError) as e:
                 logger.error(e)
                 logger.error("Timed out, reconnecting after 10s..")
                 time.sleep(10.0)
@@ -383,6 +383,7 @@ class MatrixClient:
     async def _handle_whoami(self, room, event):
         your_id = event.sender
         my_id = self.config.creds.user_id
+        raise KeyError
         await self.send_msg(room.room_id, f"- I am: `{my_id}`\n- You are: `{your_id}`")

     async def _handle_ruok(self, room, event):

Then send a !whoami message, and the bot disconnects. Calls to the webhook block until it connects again.

Currently, it seems that the webhook http server does not respond to queries while the Matrix client is not running with `self.nio.sync_forever`. A way to replicate this ```diff diff --git a/notflixbot/matrix.py b/notflixbot/matrix.py index daa9b6d..4aef02e 100644 --- a/notflixbot/matrix.py +++ b/notflixbot/matrix.py @@ -115,7 +115,7 @@ class MatrixClient: try: logger.info("Matrix client syncing forever") return await self.nio.sync_forever(timeout=3000, full_state=True) - except (asyncio.exceptions.TimeoutError, aiohttp.client_exceptions.ClientOSError) as e: + except (KeyError, asyncio.exceptions.TimeoutError, aiohttp.client_exceptions.ClientOSError) as e: logger.error(e) logger.error("Timed out, reconnecting after 10s..") time.sleep(10.0) @@ -383,6 +383,7 @@ class MatrixClient: async def _handle_whoami(self, room, event): your_id = event.sender my_id = self.config.creds.user_id + raise KeyError await self.send_msg(room.room_id, f"- I am: `{my_id}`\n- You are: `{your_id}`") async def _handle_ruok(self, room, event): ``` Then send a `!whoami` message, and the bot disconnects. Calls to the webhook block until it connects again.
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: ben/notflixbot#4
No description provided.