Add stderr diagnostics and structured httpx timeout to dsm_client
- Write progress markers to stderr at each lazy-init step so Claude Desktop logs show exactly where a timeout occurs - Replace flat timeout=30 integer with httpx.Timeout(connect=10, read=30, write=10, pool=5) to fail fast on connection issues instead of waiting up to 90 s across three sequential requests Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,7 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import sys
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
import httpx
|
||||
@@ -130,11 +131,19 @@ class DsmClient:
|
||||
async with self._init_lock:
|
||||
if self._initialized: # re-check inside lock
|
||||
return
|
||||
sys.stderr.write(f"[dsm] Connecting to {self._base_url}...\n")
|
||||
sys.stderr.flush()
|
||||
logger.debug("Lazy init: querying API info from %s", self._base_url)
|
||||
await self.query_api_info()
|
||||
sys.stderr.write(f"[dsm] API info OK ({len(self._api_cache)} APIs)\n")
|
||||
sys.stderr.flush()
|
||||
if self._auth_manager:
|
||||
sys.stderr.write("[dsm] Authenticating...\n")
|
||||
sys.stderr.flush()
|
||||
logger.debug("Lazy init: authenticating")
|
||||
self._sid = await self._auth_manager.login(self)
|
||||
sys.stderr.write("[dsm] Auth OK\n")
|
||||
sys.stderr.flush()
|
||||
self._initialized = True
|
||||
logger.debug("Lazy init complete")
|
||||
|
||||
@@ -143,7 +152,7 @@ class DsmClient:
|
||||
logging.getLogger("httpcore").setLevel(logging.WARNING)
|
||||
self._http = httpx.AsyncClient(
|
||||
verify=self._verify_ssl,
|
||||
timeout=self._timeout,
|
||||
timeout=httpx.Timeout(connect=10.0, read=float(self._timeout), write=10.0, pool=5.0),
|
||||
)
|
||||
return self
|
||||
|
||||
@@ -224,6 +233,8 @@ class DsmClient:
|
||||
Raises:
|
||||
SynologyError: On API errors.
|
||||
"""
|
||||
sys.stderr.write(f"[dsm] request: {api}/{method}\n")
|
||||
sys.stderr.flush()
|
||||
await self._ensure_initialized()
|
||||
http = self._get_http()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user