From 9d52ff0c45c076f72b9eb1480ba3a0009fc752a9 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 11 Jun 2026 08:03:03 +0200 Subject: [PATCH] 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 --- src/server/services/nfo_scan_service.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/server/services/nfo_scan_service.py b/src/server/services/nfo_scan_service.py index 11b5eba..53345c8 100644 --- a/src/server/services/nfo_scan_service.py +++ b/src/server/services/nfo_scan_service.py @@ -579,8 +579,8 @@ class NfoScanService: try: from src.server.nfo.tmdb_client import get_tmdb_client - client = get_tmdb_client() - results = await client.search_tv_show(name) + async with get_tmdb_client() as client: + results = await client.search_tv_show(name) if results and results.get("results"): first_result = results["results"][0] return first_result.get("id") @@ -601,8 +601,8 @@ class NfoScanService: try: from src.server.nfo.tmdb_client import get_tmdb_client - client = get_tmdb_client() - data = await client.get_tv_show_details(tmdb_id) + async with get_tmdb_client() as client: + data = await client.get_tv_show_details(tmdb_id) return data except Exception as exc: logger.warning("TMDB fetch failed for TMDB ID %s: %s", tmdb_id, exc)