mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-04-30 23:05:51 +00:00
Fix: add asyncio timeout guard for DuckDuckGo search
DDGS's internal `timeout=10` relies on `requests` read-timeout semantics, which only measure the gap between bytes — not total wall-clock time. When the underlying HTTP connection enters CLOSE-WAIT or the server dribbles data slowly, this timeout never fires, causing `ddgs.text` to hang indefinitely via `asyncio.to_thread`. Since `asyncio.to_thread` cannot cancel the underlying OS thread, the agent's session lock is never released, blocking all subsequent messages on the same session (observed: 8+ hours of unresponsiveness). Fix: - Add `timeout` field to `WebSearchConfig` (default: 30s, configurable via config.json or NANOBOT_TOOLS__WEB__SEARCH__TIMEOUT env var) - Wrap `asyncio.to_thread` with `asyncio.wait_for` to enforce a hard wall-clock deadline Closes #2804 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
90caf5ce51
commit
6bd2950b99
@ -207,7 +207,10 @@ class WebSearchTool(Tool):
|
|||||||
from ddgs import DDGS
|
from ddgs import DDGS
|
||||||
|
|
||||||
ddgs = DDGS(timeout=10)
|
ddgs = DDGS(timeout=10)
|
||||||
raw = await asyncio.to_thread(ddgs.text, query, max_results=n)
|
raw = await asyncio.wait_for(
|
||||||
|
asyncio.to_thread(ddgs.text, query, max_results=n),
|
||||||
|
timeout=self.config.timeout,
|
||||||
|
)
|
||||||
if not raw:
|
if not raw:
|
||||||
return f"No results for: {query}"
|
return f"No results for: {query}"
|
||||||
items = [
|
items = [
|
||||||
|
|||||||
@ -155,6 +155,7 @@ class WebSearchConfig(Base):
|
|||||||
api_key: str = ""
|
api_key: str = ""
|
||||||
base_url: str = "" # SearXNG base URL
|
base_url: str = "" # SearXNG base URL
|
||||||
max_results: int = 5
|
max_results: int = 5
|
||||||
|
timeout: int = 30 # Wall-clock timeout (seconds) for search operations
|
||||||
|
|
||||||
|
|
||||||
class WebToolsConfig(Base):
|
class WebToolsConfig(Base):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user