From 9e83510c99daeb0790f41df843820f1e381cac9c Mon Sep 17 00:00:00 2001 From: Jash Shah Date: Sun, 10 May 2026 08:30:37 -0700 Subject: [PATCH] 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. --- src/lerobot/datasets/video_utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lerobot/datasets/video_utils.py b/src/lerobot/datasets/video_utils.py index 158e68cdb..512dc6d9b 100644 --- a/src/lerobot/datasets/video_utils.py +++ b/src/lerobot/datasets/video_utils.py @@ -282,7 +282,11 @@ class VideoDecoderCache: with self._lock: if video_path not in self._cache: file_handle = fsspec.open(video_path).__enter__() - decoder = VideoDecoder(file_handle, seek_mode="approximate") + try: + decoder = VideoDecoder(file_handle, seek_mode="approximate") + except Exception: + file_handle.close() + raise self._cache[video_path] = (decoder, file_handle) return self._cache[video_path][0]