Skip to content

feat(ffmpeg): stop the running exec command when its abort signal fires - #89

Merged
Project516 merged 1 commit into
masterfrom
feat/exec-abort-signal
Oct 6, 2026
Merged

Project516 merged 1 commit into
masterfrom
feat/exec-abort-signal

Conversation

@Project516

Copy link
Copy Markdown
Owner

What and why

Aborting the AbortSignal passed to exec() only rejected the promise. The command kept running in the worker and blocked every later call. Now, where SharedArrayBuffer is usable (cross-origin isolated pages, always on Node.js), exec() shares a 4-byte Int32Array with 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.

  • Exit code: 1, the same as a timeout. The promise has already rejected with AbortError by then, so callers do not see it.
  • Without SharedArrayBuffer (st core on a non-isolated page): unchanged, the abort only rejects the promise. Documented in the exec() doc comment, usage docs and CHANGELOG.
  • ffprobe() is unchanged: the patched fftools has no timeout check for it either.
  • No fftools patch change. bind.js makes Module.timeout an accessor: a set flag reads as 0 (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.
  • The flag is created per call, so aborting one call cannot stop another.

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 first Output #0 log line, abort, assert AbortError, then assert a following exec() returns 0 within 10 s. Without the fix the follow-up call never returns.

Not run locally

Needs a rebuilt core (bind.js is linked into it), which only CI builds. pnpm lint and a type check ran locally; the Module.timeout accessor was exercised in plain Node.

Noticed, not fixed

  • A signal that is already aborted when exec() is called does not reject or stop anything, because the abort event never fires. This was already the case.
  • An aborted call that was still queued behind another call runs when its turn comes; with the flag set it stops at the first check, but it is not skipped.
  • The browser suite is skipped for the st core unless the test page is cross-origin isolated; the Node suite covers both cores.

@coderabbitai

coderabbitai Bot commented Oct 6, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: cccb1fd0-f55e-4ce6-afb1-b588eaaabffd
📥 Commits

Reviewing files that changed from the base of the PR and between c8e356d and ac5aa24.

📒 Files selected for processing (10)
  • CHANGELOG.md
  • apps/website/docs/getting-started/usage.md
  • packages/ffmpeg/src/classes.ts
  • packages/ffmpeg/src/types.ts
  • packages/ffmpeg/src/worker-node-entry.mts
  • packages/ffmpeg/src/worker.ts
  • packages/types/types/index.d.ts
  • src/bind/ffmpeg/bind.js
  • tests/ffmpeg-node.test.mjs
  • tests/ffmpeg.test.js
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@project516-review-bot project516-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@Project516
Project516 merged commit 0061619 into master Oct 6, 2026
21 checks passed
@Project516
Project516 deleted the feat/exec-abort-signal branch October 6, 2026 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant