Add worker.onerror handler to reject pending Promises#933
Open
bartadaniel wants to merge 1 commit intoffmpegwasm:mainfrom
Open
Add worker.onerror handler to reject pending Promises#933bartadaniel wants to merge 1 commit intoffmpegwasm:mainfrom
bartadaniel wants to merge 1 commit intoffmpegwasm:mainfrom
Conversation
When the Worker script fails to load (e.g. due to CORS/CORP policy, network error, or 404), the Worker constructor succeeds but the onerror event fires. Without an onerror handler, all pending Promises (including the initial load() call) hang forever and never resolve or reject. This adds a worker.onerror handler that: - Rejects all pending Promises with a descriptive error - Resets the worker state so load() can be retried Fixes ffmpegwasm#532 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
✅ Deploy Preview for ffmpegwasm canceled.
|
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.
Problem
When the Worker script fails to load (e.g. due to CORS/CORP policy, network error, or 404),
new Worker()succeeds but theonerrorevent fires instead ofonmessage. Since noonerrorhandler is set, all pending Promises — including the initialload()call — hang forever. They never resolve or reject.This is a significant issue because:
await ffmpeg.load()never returns, blocking the entire applicationThis affects any environment where the worker script URL might be blocked or unavailable (CORP headers, CSP, CDN outages, bundler misconfiguration, etc.).
Fix
Adds a
worker.onerrorhandler in#registerHandlers()that:ERROR_WORKERerror#worker = null,loaded = false) so thatload()can be retried by the callerThe implementation follows the same pattern used by
terminate()for rejecting pending Promises.Changes
packages/ffmpeg/src/classes.ts: Addworker.onerrorhandler in#registerHandlers()packages/ffmpeg/src/errors.ts: AddERROR_WORKERerror constantTesting
terminate().Fixes #532