Repository navigation
Closed
Description
Hi, thank you for your amazing library. Recently I met a problem related to asyncify stack memory region.
Run this code in node.js:
const { newAsyncContext } = require('quickjs-emscripten');
async function main() {
const context = await newAsyncContext();
let times = 0;
const fooHandle = context.newAsyncifiedFunction('foo', async () => {
times++;
console.log('foo called', times);
});
fooHandle.consume((fn) => context.setProp(context.global, 'foo', fn));
await context.evalCodeAsync(`
function a(){
foo();
a();
}
a();
`);
}
main();And it will output:
foo called 1
foo called 2
foo called 3
foo called 4
foo called 5
foo called 6
foo called 7
foo called 8
foo called 9
foo called 10
foo called 11
foo called 12
Aborted(RuntimeError: unreachable)
/home/yar2001/Documents/code/warriors-mono/node/node_modules/quickjs-emscripten/dist/generated/emscripten-module.WASM_RELEASE_ASYNCIFY.js:147
a.onAbort(b); b = "Aborted(" + b + ")"; B(b); H = !0; b = new WebAssembly.RuntimeError(b + ". Build with -sASSERTIONS for more info."); l(b); throw b; }
^
RuntimeError: Aborted(RuntimeError: unreachable). Build with -sASSERTIONS for more info.
at F (/home/yar2001/Documents/code/warriors-mono/node/node_modules/quickjs-emscripten/dist/generated/emscripten-module.WASM_RELEASE_ASYNCIFY.js:147:71)
at V (/home/yar2001/Documents/code/warriors-mono/node/node_modules/quickjs-emscripten/dist/generated/emscripten-module.WASM_RELEASE_ASYNCIFY.js:195:13)
at Aa.c.<computed> (/home/yar2001/Documents/code/warriors-mono/node/node_modules/quickjs-emscripten/dist/generated/emscripten-module.WASM_RELEASE_ASYNCIFY.js:202:87)
at /home/yar2001/Documents/code/warriors-mono/node/node_modules/quickjs-emscripten/dist/generated/emscripten-module.WASM_RELEASE_ASYNCIFY.js:217:66
at /home/yar2001/Documents/code/warriors-mono/node/node_modules/quickjs-emscripten/dist/module.js:130:25
Node.js v18.13.0
The aborted(runtimeerror: unreachable) error is likely caused by a stack overflow in the asyncify stack memory region. Notice that the function is nested 12 times and is unsuitable for some use cases (such as a little complicated web service). The linker option ASYNCIFY_STACK_SIZE is related to the size of the memory region, so maybe we can increase it to 81920 or more (20x than default).
Metadata
Metadata
Assignees
Labels
No labels
Activity
justjake commentedon Apr 19, 2023
Absolutely, I’m glad to accept a PR.
Squashed 'vendor/quickjs/' changes from 36911f0..e5fd391
Squashed 'vendor/quickjs/' changes from 36911f0..f113949
Squashed 'vendor/quickjs/' changes from 36911f0..f113949
Squashed 'vendor/quickjs/' changes from 36911f0..f113949
Update vendored QuickJS to 2025-09-13 (rebased) (#243)
Update vendored QuickJS to 2025-09-13 (rebased) (justjake#243)