Skip to content

Fall through to the standard path when a COS compile fails - #28187

Open
tomayac wants to merge 2 commits into
emscripten-core:mainfrom
tomayac:cos-await-instantiate
Open

tomayac wants to merge 2 commits into
emscripten-core:mainfrom
tomayac:cos-await-instantiate

Conversation

@tomayac

@tomayac tomayac commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

With -sCROSS_ORIGIN_STORAGE, instantiateAsync() returned the promise from cosInstantiateStream() without awaiting it. A compile failure on the cache-hit or cache-miss path therefore skipped the surrounding catch and rejected module instantiation, while the comments say it falls through to the standard path. One realistic trigger is a server that answers the .wasm URL with an HTML fallback page.

This change awaits both calls, so the failure reaches the fallback. A hit with bad bytes now refetches from the network, and a failed miss falls through to the standard streaming path.

The new browser.test_cross_origin_storage_bad_hit test stubs navigator.crossOriginStorage to return bytes that do not compile and to refuse writes, so it runs without the COS extension. I checked the same behavior against a 6.0.13 build of SQLite Wasm in Chromium: without the change, init rejects with CompileError; with it, the module loads from the network.

`instantiateAsync()` returned the promise from `cosInstantiateStream()`
without awaiting it, so a compile failure on the cache-hit or cache-miss
path skipped the surrounding `catch` and rejected module instantiation.
Await it so the failure reaches the fallback, as the comments describe.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request ensures that when using -sCROSS_ORIGIN_STORAGE, a Wasm file that fails to compile on the cache-hit or cache-miss path correctly falls through to the standard loading path. This is implemented by adding await to the cosInstantiateStream calls inside the try-catch blocks in src/preamble.js, ensuring compilation errors are caught. A new browser test, test_cross_origin_storage_bad_hit, has been added to verify this fallback behavior. There are no review comments, so I have no feedback to provide.

Comment thread ChangeLog.md Resolved
Comment thread test/test_browser.py Resolved
Comment thread ChangeLog.md Resolved
@tomayac
tomayac requested a review from sbc100 November 6, 2026 16:05
@tomayac
tomayac enabled auto-merge (squash) November 6, 2026 16:05

This branch has not been deployed

No deployments
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.

2 participants