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:
2026-04-13 15:38:37 +02:00
parent 61cbf41900
commit 737c816ee7
+12 -1
View File
@@ -12,6 +12,7 @@ from __future__ import annotations
import asyncio import asyncio
import logging import logging
import sys
from typing import TYPE_CHECKING, Any from typing import TYPE_CHECKING, Any
import httpx import httpx
@@ -130,11 +131,19 @@ class DsmClient:
async with self._init_lock: async with self._init_lock:
if self._initialized: # re-check inside lock if self._initialized: # re-check inside lock
return 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) logger.debug("Lazy init: querying API info from %s", self._base_url)
await self.query_api_info() 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: if self._auth_manager:
sys.stderr.write("[dsm] Authenticating...\n")
sys.stderr.flush()
logger.debug("Lazy init: authenticating") logger.debug("Lazy init: authenticating")
self._sid = await self._auth_manager.login(self) self._sid = await self._auth_manager.login(self)
sys.stderr.write("[dsm] Auth OK\n")
sys.stderr.flush()
self._initialized = True self._initialized = True
logger.debug("Lazy init complete") logger.debug("Lazy init complete")
@@ -143,7 +152,7 @@ class DsmClient:
logging.getLogger("httpcore").setLevel(logging.WARNING) logging.getLogger("httpcore").setLevel(logging.WARNING)
self._http = httpx.AsyncClient( self._http = httpx.AsyncClient(
verify=self._verify_ssl, 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 return self
@@ -224,6 +233,8 @@ class DsmClient:
Raises: Raises:
SynologyError: On API errors. SynologyError: On API errors.
""" """
sys.stderr.write(f"[dsm] request: {api}/{method}\n")
sys.stderr.flush()
await self._ensure_initialized() await self._ensure_initialized()
http = self._get_http() http = self._get_http()