Skip to content

fix: guard asyncify_stop_unwind() for async web API import unwinds (issue #7)#26

Closed
JosefVacha wants to merge 1 commit into
6over3:mainfrom
JosefVacha:fix-async-web-api-issue-7
Closed

fix: guard asyncify_stop_unwind() for async web API import unwinds (issue #7)#26
JosefVacha wants to merge 1 commit into
6over3:mainfrom
JosefVacha:fix-async-web-api-issue-7

Conversation

@JosefVacha

Copy link
Copy Markdown

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:

  • pl_asyncify_unwind_buf != NULL -> set by zeroperl's own asyncify_start_unwind() macro for C-level unwinds (setjmp/longjmp/scan) -> safe to call asyncify_stop_unwind() and dispatch.
  • pl_asyncify_unwind_buf == NULL -> normal exit or an async-import unwind -> do NOT clear __asyncify_state; let the asyncify-wasm runtime handle it.

Changes

  • Only stubs/runtime.c modified
  • Added proper comment explaining the logic
  • Moved extern void *pl_asyncify_unwind_buf; to file scope

Fixes

Closes #7

Based on PR #25 by @itsbryanman

…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
@JosefVacha JosefVacha closed this by deleting the head repository May 25, 2026
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.

Asynchronous Web APIs

1 participant