From 8a6432e5f8defae81b6e2ed7022f12400a2263f5 Mon Sep 17 00:00:00 2001 From: sylvain Date: Mon, 9 Mar 2026 16:44:59 +0000 Subject: [PATCH] fix: dispatch XMPP message callback in thread to avoid blocking asyncio loop The LLM call (up to 300s) was blocking the slixmpp asyncio event loop, preventing keepalive pings and causing the server to close the connection. All XMPP message handling now runs in a daemon thread. Co-Authored-By: Claude Sonnet 4.6 --- agents_core/xmpp_client.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/agents_core/xmpp_client.py b/agents_core/xmpp_client.py index 74ac6b1..9319848 100644 --- a/agents_core/xmpp_client.py +++ b/agents_core/xmpp_client.py @@ -129,10 +129,19 @@ class XMPPClient: logger.debug(f"[XMPP] Message ignoré (non autorisé) : {sender}") return if self._message_callback: - try: - self._message_callback(sender, body, is_muc) - except Exception as e: - logger.error(f"[XMPP] Erreur callback : {e}") + # Dispatch dans un thread pour ne pas bloquer la boucle asyncio XMPP + threading.Thread( + target=self._dispatch_callback, + args=(sender, body, is_muc), + daemon=True, + name="xmpp-handler", + ).start() + + def _dispatch_callback(self, sender: str, body: str, is_muc: bool): + try: + self._message_callback(sender, body, is_muc) + except Exception as e: + logger.error(f"[XMPP] Erreur callback : {e}") def send_message(self, to: str, body: str, is_muc: bool = False): """Envoie un message XMPP (direct ou MUC)."""