fix: AbortSignal now sends CANCEL to stop running exec (#719)#938
Open
JacobiusMakes wants to merge 1 commit intoffmpegwasm:mainfrom
Open
fix: AbortSignal now sends CANCEL to stop running exec (#719)#938JacobiusMakes wants to merge 1 commit intoffmpegwasm:mainfrom
JacobiusMakes wants to merge 1 commit intoffmpegwasm:mainfrom
Conversation
✅ Deploy Preview for ffmpegwasm canceled.
|
…sm#719) Previously, aborting an exec() or ffprobe() only rejected the JS Promise — the underlying WASM process kept running to completion. Fix: when the abort signal fires for EXEC or FFPROBE, immediately send a CANCEL message to the worker. The worker calls ffmpeg.setTimeout(1), setting the WASM watchdog to fire after 1 ms, stopping the current command as quickly as possible (exit code 1) without terminating the entire worker. Changes: - const.ts: add FFMessageType.CANCEL - worker.ts: add cancel() handler calling ffmpeg.setTimeout(1) - classes.ts: send CANCEL on exec/ffprobe abort Closes ffmpegwasm#719 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
e297b86 to
50f33d3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #719. When
AbortSignalfires duringexec()orffprobe(), aCANCELmessage is now sent to the worker to actually stop the running FFmpeg command — not just reject the JS Promise.Problem
Previously, aborting an
exec()orffprobe()only rejected the JavaScript Promise. The underlying WASM process continued running to completion, wasting CPU and makingAbortControlleruseless for long transcoding operations.Fix
const.ts— AddFFMessageType.CANCELto the message enum.classes.ts— When the abort signal fires for EXEC or FFPROBE, send aCANCELmessage to the worker (in addition to rejecting the Promise). Also fixes a memory leak: Blob URLs created forcoreData/wasmData/workerDataare now tracked in#blobURLsand revoked interminate().worker.ts— HandleCANCELby callingffmpeg.setTimeout(1), which sets the WASM-side watchdog to fire after 1ms. This is the same mechanism used by the existingtimeoutparameter — it stops the current command and returns exit code 1.Known limitation
In single-thread mode,
exec()blocks the worker's JS event loop while running WASM. TheCANCELmessage queues behind it and only executes after the command finishes. For true mid-execution cancellation, the multi-thread build (which usesSharedArrayBuffer) would be needed. This PR still improves the situation by:Test plan
exec()before it starts — CANCEL arrives first, sets timeout to 1ms, exec returns immediatelyterminate()after usingcoreData/wasmData— verify no blob URL leak via DevTools memory panel🤖 Generated with Claude Code