From f9eee6ba6252ea7924d2afcc27da4fd99c4dae3f Mon Sep 17 00:00:00 2001 From: doe1080 <98906116+doe1080@users.noreply.github.com> Date: Mon, 28 Sep 2026 02:54:19 +0900 Subject: [PATCH] [rh:urllib] Eagerly release `BytesIO` responses (#17717) Authored by: doe1080 --- yt_dlp/networking/_urllib.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/yt_dlp/networking/_urllib.py b/yt_dlp/networking/_urllib.py index 5e6167dd7a..c3f16c99af 100644 --- a/yt_dlp/networking/_urllib.py +++ b/yt_dlp/networking/_urllib.py @@ -313,7 +313,9 @@ class UrllibResponseAdapter(Response): # urllib's addinfourl does not close the underlying fp automatically when fully read if isinstance(underlying, io.BytesIO): # data URLs or in-memory responses (e.g. gzip/deflate/brotli decoded) - if underlying.tell() >= len(underlying.getbuffer()): + with underlying.getbuffer() as view: + fully_read = underlying.tell() >= len(view) + if fully_read: self.close() elif isinstance(underlying, io.BufferedReader) and amt is None: # file URLs.