From 86e76480754475564b3051af22d55217a23c395e Mon Sep 17 00:00:00 2001 From: Mattias Thall Date: Wed, 27 May 2026 01:21:36 +0200 Subject: [PATCH] Fix _meta_run: hold lock for entire yt-dlp execution, not just scheduling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously the lock was released before _run(), so multiple threads could fire yt-dlp processes simultaneously — completely defeating the rate limiter. Now the lock is held through the subprocess call and released in finally. Co-Authored-By: Claude Sonnet 4.6 --- backend/services/ytdlp.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/services/ytdlp.py b/backend/services/ytdlp.py index 1bd5432..259eec3 100644 --- a/backend/services/ytdlp.py +++ b/backend/services/ytdlp.py @@ -33,8 +33,10 @@ def _meta_run(args: list[str], timeout: int = 60) -> tuple[str, str, int]: wait = _META_MIN_GAP - (now - _meta_last_call) if wait > 0: time.sleep(wait + random.uniform(0.5, 2.5)) - _meta_last_call = time.monotonic() - return _run(args, timeout=timeout) + try: + return _run(args, timeout=timeout) + finally: + _meta_last_call = time.monotonic() def _parse_date(date_str: str | None) -> datetime | None: