Repository navigation
feat(ffmpeg): stop the running exec command when its abort signal fires - #89
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 54 minutes. View limit detailsLimit details: You’ve used the included review currently available. Review configuration: ⚙️ Run configuration
📒 Files selected for processing (10)
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 |
There was a problem hiding this comment.
This PR adds support for stopping a running exec() command when an AbortSignal fires, using a SharedArrayBuffer-backed flag polled by the ffmpeg core. The abort flag is created per call and only used when SharedArrayBuffer is available (cross-origin isolated pages and Node.js); otherwise the abort only rejects the promise. The implementation modifies the Module.timeout accessor in bind.js to return 0 when the flag is set, causing the command to exit like a timeout.
review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict approve
What and why
Aborting the
AbortSignalpassed toexec()only rejected the promise. The command kept running in the worker and blocked every later call. Now, whereSharedArrayBufferis usable (cross-origin isolated pages, always on Node.js),exec()shares a 4-byteInt32Arraywith the worker per call and the abort sets it. The core polls it at the same place it polls the timeout, so the command stops like a timeout does.1, the same as a timeout. The promise has already rejected withAbortErrorby then, so callers do not see it.SharedArrayBuffer(st core on a non-isolated page): unchanged, the abort only rejects the promise. Documented in theexec()doc comment, usage docs and CHANGELOG.ffprobe()is unchanged: the patched fftools has no timeout check for it either.bind.jsmakesModule.timeoutan accessor: a set flag reads as0(timed out), and a flag with no timeout reads as a huge value so ffmpeg takes the existing 5 ms polling path instead of the 500 ms report period. Setting a real timeout works as before.Upstream: ffmpegwasm#978.
Tests
Browser suite (skipped unless
crossOriginIsolated) and Node suite (st and mt): start-re -f lavfi -i testsrc ... -f null -, which never ends alone, wait for its firstOutput #0log line, abort, assertAbortError, then assert a followingexec()returns 0 within 10 s. Without the fix the follow-up call never returns.Not run locally
Needs a rebuilt core (
bind.jsis linked into it), which only CI builds.pnpm lintand a type check ran locally; theModule.timeoutaccessor was exercised in plain Node.Noticed, not fixed
exec()is called does not reject or stop anything, because the abort event never fires. This was already the case.