1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-11-14 13:35:15 +00:00

[networking] Ensure underlying file object is closed when fully read (#14935)

Fixes https://github.com/yt-dlp/yt-dlp/issues/14891

Authored by: coletdjnz
This commit is contained in:
coletdjnz
2025-11-08 18:30:43 +13:00
committed by GitHub
parent 73fd850d17
commit 5767fb4ab1
5 changed files with 124 additions and 16 deletions

View File

@@ -554,12 +554,16 @@ class Response(io.IOBase):
# Expected errors raised here should be of type RequestError or subclasses.
# Subclasses should redefine this method with more precise error handling.
try:
return self.fp.read(amt)
res = self.fp.read(amt)
if self.fp.closed:
self.close()
return res
except Exception as e:
raise TransportError(cause=e) from e
def close(self):
self.fp.close()
if not self.fp.closed:
self.fp.close()
return super().close()
def get_header(self, name, default=None):