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 <noreply@anthropic.com>
This commit is contained in:
@@ -129,10 +129,19 @@ class XMPPClient:
|
|||||||
logger.debug(f"[XMPP] Message ignoré (non autorisé) : {sender}")
|
logger.debug(f"[XMPP] Message ignoré (non autorisé) : {sender}")
|
||||||
return
|
return
|
||||||
if self._message_callback:
|
if self._message_callback:
|
||||||
try:
|
# Dispatch dans un thread pour ne pas bloquer la boucle asyncio XMPP
|
||||||
self._message_callback(sender, body, is_muc)
|
threading.Thread(
|
||||||
except Exception as e:
|
target=self._dispatch_callback,
|
||||||
logger.error(f"[XMPP] Erreur callback : {e}")
|
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):
|
def send_message(self, to: str, body: str, is_muc: bool = False):
|
||||||
"""Envoie un message XMPP (direct ou MUC)."""
|
"""Envoie un message XMPP (direct ou MUC)."""
|
||||||
|
|||||||
Reference in New Issue
Block a user