fix: guard asyncify_stop_unwind() for async web API import unwinds (issue #7)#26
Closed
JosefVacha wants to merge 1 commit into
Closed
fix: guard asyncify_stop_unwind() for async web API import unwinds (issue #7)#26JosefVacha wants to merge 1 commit into
JosefVacha wants to merge 1 commit into
Conversation
…ssue #7) Only call asyncify_stop_unwind() when pl_asyncify_unwind_buf is non-NULL, which indicates a C-level (setjmp/longjmp/scan) unwind. When an asyncify import like call_host_function triggers an unwind, the transform bypasses our macro so pl_asyncify_unwind_buf stays NULL. Calling asyncify_stop_unwind() in that case clears __asyncify_state from 1 (UNWINDING) to 0 before the export returns to JS, hiding the pending async op from asyncify-wasm. Fixes #7 Based on PR #25 by @itsbryanman
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 (Root Cause)
The runtime loop in stubs/runtime.c unconditionally called asyncify_stop_unwind() after every return from main(). When an asyncify import (call_host_function) triggered an unwind, this call cleared __asyncify_state from 1 (UNWINDING) to 0 before the export returned to JavaScript. The asyncify-wasm host then saw state 0, assumed normal termination, and never awaited the pending Promise -> the async call was silently dropped.
Solution (The Fix)
Introduced a guard using the existing variable pl_asyncify_unwind_buf:
Changes
Fixes
Closes #7
Based on PR #25 by @itsbryanman