fix(wasm): ccall({async:true}) — fixes ASYNCIFY streaming#34
Merged
Conversation
Root cause of all WASM hanging: Module._wasm_generate_async() is a
DIRECT function call that does NOT return a Promise even with ASYNCIFY.
Only Module.ccall('fn', ..., {async: true}) makes Emscripten create
the async wrapper that properly unwinds/rewinds the C stack.
The try/catch was silently falling through to Module._wasm_generate()
(the sync version), blocking the entire main thread.
Fix: replace Module._wasm_generate_async() with Module.ccall() using
{async: true}. Add ccall/cwrap to EXPORTED_RUNTIME_METHODS.
This is the documented Emscripten ASYNCIFY pattern:
https://emscripten.org/docs/porting/asyncify.html#making-async-web-apis-behave-as-if-they-were-synchronous
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
The actual root cause of ALL WASM hanging
Module._wasm_generate_async(ptr, 0.7, 256)is a direct C function call. Even with ASYNCIFY enabled, direct calls do NOT return Promises. Theawaitresolves immediately, and whenemscripten_sleep(0)fires inside the C code, the ASYNCIFY unwind has nowhere to go — it hangs.The
try/catchwas then callingModule._wasm_generate()(sync), which blocks the entire main thread. We never saw the error because the catch was silent.Fix
Replace with
Module.ccall('wasm_generate_async', ..., {async: true}). This is Emscripten's documented ASYNCIFY pattern —ccallwith{async: true}creates a proper async wrapper that returns a Promise and correctly handles sleep/unwind/rewind cycles.Added
ccallandcwraptoEXPORTED_RUNTIME_METHODS.This explains everything
🤖 Generated with Claude Code