fix: ensure SaveWEBM container is always closed on encoding error#13358
fix: ensure SaveWEBM container is always closed on encoding error#13358octo-patch wants to merge 2 commits intoComfy-Org:masterfrom
Conversation
…t' (fixes Comfy-Org#13300) The 'default' compression method maps to WebP method=4, which is significantly slower than method=0 ('fastest'). For animated WebP with many frames (e.g. 120 frames of video), this resulted in encoding times of 2+ minutes. Changing the node default to 'fastest' (method=0) reduces encoding time by ~3x while still allowing users to select higher compression methods when needed.
…-Org#9115) Wrap the av.Container operations in SaveWEBM.execute with try/finally to guarantee container.close() is called even when an exception occurs during encoding (e.g. OOM, codec error). Without this, the output file handle could remain open, causing 'file is open in Python' errors on Windows when trying to delete or overwrite the output file. Consistent with the pattern already used in encode_single_frame() and decode_single_frame() in comfy_extras/nodes_lt.py.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe pull request makes two targeted modifications to the ComfyUI extras module. The first change adds an explicit UI default value of 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Fixes #9115
Problem
SaveWEBM.executeopens a PyAVContainerwithav.open(..., mode=\"w\")and callscontainer.close()only at the end of the function. If any exception occurs during encoding (e.g. out-of-memory, codec error, invalid frame dimensions),container.close()is never called. The output file handle then remains open in the Python process until the garbage collector eventually destroys theContainerobject.On Windows this manifests as a file-lock error: after a failed or interrupted WEBM encode, users cannot delete or overwrite the output file because Python still holds it open. Even on Linux it can exhaust file descriptors under high load or repeated failures.
Solution
Wrap all operations between
av.openandcontainer.close()in atry/finallyblock so thatcontainer.close()is guaranteed to run regardless of exceptions. This matches the pattern already used incomfy_extras/nodes_lt.pyforencode_single_frameanddecode_single_frame.Testing
try/finallyensurescontainer.close()is called even when an exception is raised during encoding.