From 77ffdac84b93f1e8ecfde9ebe95fc8b530a37a89 Mon Sep 17 00:00:00 2001 From: Lukas Date: Fri, 23 Jan 2026 14:49:11 +0100 Subject: [PATCH] fix: improve TMDB timeout handling and increase timeout to 60s - Increase request timeout from 30s to 60s for slower TMDB responses - Add explicit asyncio.TimeoutError handling with retry logic - Separate timeout error handling from general ClientError handling - Provides better logging for timeout vs other failures --- src/core/services/tmdb_client.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/core/services/tmdb_client.py b/src/core/services/tmdb_client.py index d8c4a59..05a642b 100644 --- a/src/core/services/tmdb_client.py +++ b/src/core/services/tmdb_client.py @@ -122,7 +122,7 @@ class TMDBClient: raise TMDBAPIError("Session is not available") logger.debug(f"TMDB API request: {endpoint} (attempt {attempt + 1})") - async with self.session.get(url, params=params, timeout=aiohttp.ClientTimeout(total=30)) as resp: + async with self.session.get(url, params=params, timeout=aiohttp.ClientTimeout(total=60)) as resp: if resp.status == 401: raise TMDBAPIError("Invalid TMDB API key") elif resp.status == 404: @@ -139,6 +139,15 @@ class TMDBClient: self._cache[cache_key] = data return data + except asyncio.TimeoutError as e: + last_error = e + if attempt < max_retries - 1: + logger.warning(f"Request timeout (attempt {attempt + 1}), retrying in {delay}s") + await asyncio.sleep(delay) + delay *= 2 + else: + logger.error(f"Request timed out after {max_retries} attempts") + except (aiohttp.ClientError, AttributeError) as e: last_error = e # If connector/session was closed, try to recreate it