apache/shenyu · error · ShenyuWasmInitException
memory not available in wasm file
Error message
memory not available in wasm file: ${wasmName} What it means
After instantiating the WebAssembly module with Chicory, WasmLoader requires the module to export a linear memory. When instance.memory() returns null — the compiled .wasm has no exported memory — it throws ShenyuWasmInitException because the gateway cannot read/write the module's data without it.
Solutions
- Recompile the wasm source so linear memory is exported (e.g. in C with clang: -Wl,--export-memory; in wat: (export "memory" (memory 0))).
- Verify the module's exports with wasm-objdump -x module.wasm or wasm-tools and confirm a memory export exists.
- Use a wasm binary produced by the ShenYu plugin toolchain/template, which guarantees an exported memory.
- If you cannot change the binary, wrap it in a module that re-exports memory or switch to a runtime path that does not require host-side memory access.
Example fix
// wat before (module (memory (export "mem") 1)) // after (module (memory 1) (export "memory" (memory 0)))
Defensive patterns
Strategy: validation
Validate before calling
// Build-time / pre-load check with wasm tooling // wasm-objdump -x module.wasm | grep -q 'memory' || echo 'ERROR: no memory export'
Try / catch
try {
WasmLoader loader = new MyWasmPlugin();
} catch (ShenyuWasmInitException e) {
if (e.getMessage().startsWith("memory not available")) { /* rebuild wasm with exported memory */ }
throw e;
} Prevention
- Compile with memory exported (clang: -Wl,--export-memory).
- Verify exports with wasm-objdump/wasm-tools before shipping the binary.
- Use the standard ShenYu wasm plugin build template.
When it happens
Trigger: Loading a .wasm module whose exports lack 'memory' (e.g. built without exported memory or with memory not exported in the wasm binary), during WasmLoader construction.
Common situations: Compiling C/Rust/AssemblyScript to wasm with memory kept internal or memory64/exotic memory settings; using a wasm binary built for a different runtime that does not export memory; hand-written wat files missing an (export "memory" ...) clause.
Related errors
- Can't find wasm file
- no more memory can be used !
- The task queue does not have executor!
- WASI proc_exit( ) from
- dynamic build JsonMarshaller descriptor is fail
AI-assisted analysis of apache/shenyu@567142e072 (2026-09-12).
Data as JSON: /api/errors/6026ac0bfb9e04bf.
Report an issue: GitHub.
Appendix: source
Thrown at shenyu-plugin/shenyu-plugin-wasm-api/src/main/java/org/apache/shenyu/plugin/wasm/api/loader/WasmLoader.java:150
this.instance = Instance.builder(module)
.withImportValues(store.toImportValues())
.withStart(false)
.build();
}
// Call _initialize if present (required by TinyGo -target wasm-unknown).
try {
ExportFunction initFn = instance.export("_initialize");
if (Objects.nonNull(initFn)) {
initFn.apply();
LOG.debug("Called _initialize for {}", wasmName);
}
} catch (com.dylibso.chicory.wasm.InvalidException e) {
LOG.debug("No _initialize export in {}", wasmName);
}
if (Objects.isNull(instance.memory())) {
throw new ShenyuWasmInitException("memory not available in wasm file: " + wasmName);
}
} catch (IOException e) {
throw new ShenyuWasmInitException(e);
}
}
private void registerWasiStubs(final Store store) {
// Use Chicory's built-in full WASI preview1 implementation for comprehensive
// WASI function coverage, matching the previous wasmtime-java behavior.
// Only inherit stdout/stderr so WASM guest output (e.g. Go println,
// Rust eprintln!) is visible for debugging. Avoid inheriting the full
// system context (env/args/filesystem) for security hardening.
var options = com.dylibso.chicory.wasi.WasiOptions.builder()
.withStdout(System.out)
.withStderr(System.err)
.build();
var wasi = com.dylibso.chicory.wasi.WasiPreview1.builder()
.withOptions(options)View on GitHub (pinned to 567142e072)