fix(datasets): close file handle on VideoDecoder init failure in cache (#3542)

If VideoDecoder() raises during initialization, the fsspec file handle
was leaked since it was opened via __enter__() but never closed on the
exception path. Now explicitly closes the handle before re-raising.
This commit is contained in:
Jash Shah
2026-05-10 08:30:37 -07:00
committed by GitHub
parent 1f7b03f5f2
commit 9e83510c99
+4
View File
@@ -282,7 +282,11 @@ class VideoDecoderCache:
with self._lock: with self._lock:
if video_path not in self._cache: if video_path not in self._cache:
file_handle = fsspec.open(video_path).__enter__() file_handle = fsspec.open(video_path).__enter__()
try:
decoder = VideoDecoder(file_handle, seek_mode="approximate") decoder = VideoDecoder(file_handle, seek_mode="approximate")
except Exception:
file_handle.close()
raise
self._cache[video_path] = (decoder, file_handle) self._cache[video_path] = (decoder, file_handle)
return self._cache[video_path][0] return self._cache[video_path][0]