fix: use async context manager for TMDBClient to prevent resource leak

The TMDBClient was being instantiated but never closed, causing 'Unclosed
client session' errors in the logs. Fixed by using 'async with' context
manager which properly calls close() on exit.

Changes:
- _lookup_tmdb_id_by_name: wrapped client in async with
- _fetch_tmdb_data: wrapped client in async with
This commit is contained in:
2026-06-11 08:03:03 +02:00
parent ee5d719f37
commit 9d52ff0c45

View File

@@ -579,8 +579,8 @@ class NfoScanService:
try: try:
from src.server.nfo.tmdb_client import get_tmdb_client from src.server.nfo.tmdb_client import get_tmdb_client
client = get_tmdb_client() async with get_tmdb_client() as client:
results = await client.search_tv_show(name) results = await client.search_tv_show(name)
if results and results.get("results"): if results and results.get("results"):
first_result = results["results"][0] first_result = results["results"][0]
return first_result.get("id") return first_result.get("id")
@@ -601,8 +601,8 @@ class NfoScanService:
try: try:
from src.server.nfo.tmdb_client import get_tmdb_client from src.server.nfo.tmdb_client import get_tmdb_client
client = get_tmdb_client() async with get_tmdb_client() as client:
data = await client.get_tv_show_details(tmdb_id) data = await client.get_tv_show_details(tmdb_id)
return data return data
except Exception as exc: except Exception as exc:
logger.warning("TMDB fetch failed for TMDB ID %s: %s", tmdb_id, exc) logger.warning("TMDB fetch failed for TMDB ID %s: %s", tmdb_id, exc)