Skip to content

Fix sequential awaited calls in Asyncify runtimes#265

Open
TheBoyWhoLivedd wants to merge 2 commits into
justjake:mainfrom
TheBoyWhoLivedd:fix-asyncify-sequential-awaits
Open

Fix sequential awaited calls in Asyncify runtimes#265
TheBoyWhoLivedd wants to merge 2 commits into
justjake:mainfrom
TheBoyWhoLivedd:fix-asyncify-sequential-awaits

Conversation

@TheBoyWhoLivedd

Copy link
Copy Markdown

Summary

This fixes runtime corruption caused by multiple sequential awaited host calls within one guest execution.

  • Generate { async: true } for Asyncify cwrap bindings in release builds.
  • Add QuickJSAsyncRuntime.executePendingJobsAsync().
  • Share pending-job result handling between the synchronous and asynchronous runtime implementations.
  • Add a regression covering three sequential awaited host calls and subsequent context reuse.
  • Regenerate the affected release Asyncify variants.

Cause

The generated debug bindings passed { async: true } to Emscripten's cwrap, but release bindings omitted it.

Emscripten requires this option when a wrapped export may suspend. Without it, a release build can continue as though the call returned synchronously, leaving the runtime in an invalid state.

QTS_ExecutePendingJob_MaybeAsync may suspend when a pending guest job calls an asyncified host function, so Asyncify runtimes also need an awaitable pending-job driver:

const result = await runtime.executePendingJobsAsync()

Reproduction

https://github.com/TheBoyWhoLivedd/quickjs-emscripten-asyncify-multi-await-repro

Fixes #258

Generate async cwrap bindings whenever an exported function may suspend, including in release builds.

Add an asynchronous pending-job driver so guest jobs can safely resume through multiple awaited host calls without corrupting the runtime.
The build regenerates and formats variant FFI files from scripts/generate.ts. Exclude those generated outputs so the pull request contains only canonical source changes.
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.

Multiple sequential await calls in evalCodeAsync fail with "Lifetime not alive"

1 participant