Skip to content

Add worker.onerror handler to reject pending Promises#933

Open
bartadaniel wants to merge 1 commit intoffmpegwasm:mainfrom
bartadaniel:fix/worker-onerror-handler
Open

Add worker.onerror handler to reject pending Promises#933
bartadaniel wants to merge 1 commit intoffmpegwasm:mainfrom
bartadaniel:fix/worker-onerror-handler

Conversation

@bartadaniel
Copy link

Problem

When the Worker script fails to load (e.g. due to CORS/CORP policy, network error, or 404), new Worker() succeeds but the onerror event fires instead of onmessage. Since no onerror handler is set, all pending Promises — including the initial load() call — hang forever. They never resolve or reject.

This is a significant issue because:

  • Callers have no way to detect the failure
  • No error is surfaced — the operation silently hangs
  • await ffmpeg.load() never returns, blocking the entire application

This 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.onerror handler in #registerHandlers() that:

  1. Rejects all pending Promises (not just the load Promise) with a descriptive ERROR_WORKER error
  2. Resets the internal worker state (#worker = null, loaded = false) so that load() can be retried by the caller

The implementation follows the same pattern used by terminate() for rejecting pending Promises.

Changes

  • packages/ffmpeg/src/classes.ts: Add worker.onerror handler in #registerHandlers()
  • packages/ffmpeg/src/errors.ts: Add ERROR_WORKER error constant

Testing

  • TypeScript compilation passes with no errors
  • The existing browser-based test suite doesn't have infrastructure for simulating Worker load failures. The fix is minimal and follows the same rejection pattern already used in terminate().

Fixes #532

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>
@netlify
Copy link

netlify bot commented Mar 4, 2026

Deploy Preview for ffmpegwasm canceled.

Name Link
🔨 Latest commit f00246e
🔍 Latest deploy log https://app.netlify.com/projects/ffmpegwasm/deploys/69a841a1bcafd80008113fef

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.

FFmpeg hangs on load and no console errors are displayed

1 participant