Skip to content

fix(jco): JSPI-suspended imports hang when they fail - #2309

Merged
vados-cosmonic merged 2 commits into
bytecodealliance:mainfrom
chenyan2002:import-rethrow
Oct 24, 2026
Merged

vados-cosmonic merged 2 commits into
bytecodealliance:mainfrom
chenyan2002:import-rethrow

Conversation

@chenyan2002

Copy link
Copy Markdown
Contributor

Problem

A sync component runs under JSPI and calls an import that rejects or throws. The guest stays suspended forever, and the export's promise never settles.

Imports from sync components that JSPI suspends go through the CallInterface trampoline in crates/js-component-bindgen/src/function_bindgen.rs. When the import throws, the async error branch rejects and exits the task, then returns task.completionPromise() to the suspended guest.

That promise settles only after #completionReady is set. The flag is set only for tasks that are isAsync or isManualAsync. A JSPI-only import task is created with isAsync: false and no isManualAsync, so the promise never settles.

Fix

In the async error branch of CallInterface, end with throw err; unless the function is async in the component-model sense (*async_). For those functions, keep return task.completionPromise();. Throwing rejects the promise that WebAssembly.Suspending is waiting on, so the guest traps and the export rejects, the same as in the sync path.

@vados-cosmonic vados-cosmonic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM 🚀

Thanks @chenyan2002 , this looks good to me in general, I'm a little worried about throwing early but I think with the fix for the async function that maybe won't be a problem?

Also I'll have to change the commits a little bit.

vados-cosmonic and others added 2 commits October 24, 2026 14:08
Co-authored-by: Yan Chen <yan.chen@fastly.com>
Co-authored-by: Yan Chen <yan.chen@fastly.com>
@vados-cosmonic
vados-cosmonic added this pull request to the merge queue Oct 24, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 24, 2026
@vados-cosmonic
vados-cosmonic added this pull request to the merge queue Oct 24, 2026
Merged via the queue into bytecodealliance:main with commit 39b2b63 Oct 24, 2026
66 checks passed
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