feat: add ZMQ timeout configurations to prevent hanging

- Add RCVTIMEO (300s) to prevent recv operations from hanging indefinitely
- Add SNDTIMEO (300s) to prevent send operations from hanging indefinitely
- Add IMMEDIATE mode to avoid message queue blocking
- Applied to both api.py and searcher_base.py ZMQ socket connections

This ensures ZMQ operations timeout gracefully instead of hanging the process
when embedding servers become unresponsive.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Andy Lee
2025-08-10 08:30:02 +00:00
parent 48c82ee3e3
commit 4de709ad4b
2 changed files with 6 additions and 0 deletions

View File

@@ -88,6 +88,9 @@ def compute_embeddings_via_server(chunks: list[str], model_name: str, port: int)
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.setsockopt(zmq.LINGER, 0) # Don't block on close
socket.setsockopt(zmq.RCVTIMEO, 300000) # 300秒接收超时
socket.setsockopt(zmq.SNDTIMEO, 300000) # 300秒发送超时
socket.setsockopt(zmq.IMMEDIATE, 1) # 立即模式,避免队列阻塞
socket.connect(f"tcp://localhost:{port}")
try:

View File

@@ -138,6 +138,9 @@ class BaseSearcher(LeannBackendSearcherInterface, ABC):
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.setsockopt(zmq.LINGER, 0) # Don't block on close
socket.setsockopt(zmq.RCVTIMEO, 300000) # 300秒接收超时
socket.setsockopt(zmq.SNDTIMEO, 300000) # 300秒发送超时
socket.setsockopt(zmq.IMMEDIATE, 1) # 立即模式,避免队列阻塞
socket.connect(f"tcp://localhost:{zmq_port}")
# Send embedding request