fix: split HTTP connect/read timeouts (Jellyfin build + qBit stats)

Every HTTP client passed an integer timeout to requests, applying the same
value to BOTH connect and read phases. A slow Jellyfin /Items page or qBit
/sync/maindata blew through the 10s read budget → ReadTimeoutError. Split
into a (connect=5s, read=60s default) tuple via shared http_timeout() helper.
The media index build worker uses a 180s read floor. Existing services with
low timeout_seconds benefit from bumping to 60+.
This commit is contained in:
Developer
2026-07-10 11:43:07 +00:00
parent 9bc8fab971
commit 044d386ac7
17 changed files with 152 additions and 29 deletions
@@ -14,6 +14,7 @@ from typing import Any
import requests
from fastapi import APIRouter, Body, Depends
from media_library_viewer_api.clients.http_timeout import http_timeout
from media_library_viewer_api.dependencies import get_settings_store
from media_library_viewer_api.services.service_resolution import resolve_service_record
from media_library_viewer_api.services.settings_store import SettingsStore
@@ -27,8 +28,10 @@ def _base_url(service: ServiceRecord) -> str:
return str(service.config.get("base_url") or "").rstrip("/")
def _timeout(service: ServiceRecord, default: int) -> int:
return int(service.config.get("timeout_seconds") or default)
def _timeout(service: ServiceRecord, default: int) -> tuple[float, float]:
"""Return a (connect, read) timeout tuple from the service config."""
read = int(service.config.get("timeout_seconds") or default)
return http_timeout(read)
def _auth_headers(service: ServiceRecord) -> dict[str, str]:
@@ -189,7 +192,7 @@ def get_prometheus_status(
grafana_url = str(service.config.get("grafana_url") or "").rstrip("/")
api_key = str(service.secrets.get("grafana_api_key") or "")
datasource_uid = str(service.config.get("datasource_uid") or "prometheus")
timeout = int(service.config.get("timeout_seconds") or 10)
timeout = int(service.config.get("timeout_seconds") or 60)
if not grafana_url or not api_key:
return _status_response(service, error="gateway_not_configured")
body = {
@@ -211,7 +214,7 @@ def get_prometheus_status(
f"{grafana_url}/api/ds/query",
json=body,
headers={"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"},
timeout=timeout,
timeout=http_timeout(timeout),
)
resp.raise_for_status()
except requests.HTTPError as exc: