fix(core): bound blocking future.result() calls so a hung dependency can't freeze the connection

Two cross-thread future.result() calls had no timeout, so a stalled
dependency blocked the thread indefinitely with no recovery:

- connection.py: a hung memory backend froze the chat thread during
  query_memory().
- tts/base.py: a stalled WebSocket send froze the audio priority thread in
  sendAudioMessage().

Add a 30s timeout and explicit TimeoutError handling at both sites. On
timeout the failure is logged and the loop proceeds (memory falls back to
None; the audio frame is skipped) instead of deadlocking. The tool-call
fan-in already uses tool_call_timeout, so it is left unchanged.
This commit is contained in:
Brad Shannon 2026-06-17 17:57:12 -04:00
parent 071ed99a32
commit 3c59c46551
2 changed files with 14 additions and 3 deletions

View file

@ -27,7 +27,7 @@ from core.utils.modules_initialize import (
) )
from core.handle.reportHandle import report, enqueue_tool_report from core.handle.reportHandle import report, enqueue_tool_report
from core.providers.tts.default import DefaultTTS from core.providers.tts.default import DefaultTTS
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor, TimeoutError as FutureTimeoutError
from core.utils.dialogue import Message, Dialogue from core.utils.dialogue import Message, Dialogue
from core.providers.asr.dto.dto import InterfaceType from core.providers.asr.dto.dto import InterfaceType
from core.handle.textHandle import handleTextMessage from core.handle.textHandle import handleTextMessage
@ -976,7 +976,13 @@ class ConnectionHandler:
future = asyncio.run_coroutine_threadsafe( future = asyncio.run_coroutine_threadsafe(
self.memory.query_memory(query), self.loop self.memory.query_memory(query), self.loop
) )
memory_str = future.result() try:
memory_str = future.result(timeout=30)
except FutureTimeoutError:
self.logger.bind(tag=TAG).error(
"Memory query timed out after 30s"
)
memory_str = None
if self.intent_type == "function_call" and functions is not None: if self.intent_type == "function_call" and functions is not None:
# 使用支持functions的streaming接口 # 使用支持functions的streaming接口

View file

@ -459,7 +459,12 @@ class TTSProviderBase(ABC):
sendAudioMessage(self.conn, sentence_type, audio_datas, text, sentence_id), sendAudioMessage(self.conn, sentence_type, audio_datas, text, sentence_id),
self.conn.loop, self.conn.loop,
) )
future.result() try:
future.result(timeout=30)
except concurrent.futures.TimeoutError:
logger.bind(tag=TAG).error(
"sendAudioMessage timed out after 30s — skipping frame"
)
# 记录输出和报告 # 记录输出和报告
if self.conn.max_output_size > 0 and text: if self.conn.max_output_size > 0 and text: