{"record":{"id":"6026ac0bfb9e04bf","repo":"apache/shenyu","slug":"memory-not-available-in-wasm-file-wasmname","errorCode":null,"errorMessage":"memory not available in wasm file: ${wasmName}","messagePattern":"memory not available in wasm file: (.+?)","errorType":"exception","errorClass":"ShenyuWasmInitException","httpStatus":null,"severity":"error","filePath":"shenyu-plugin/shenyu-plugin-wasm-api/src/main/java/org/apache/shenyu/plugin/wasm/api/loader/WasmLoader.java","lineNumber":150,"sourceCode":"                this.instance = Instance.builder(module)\n                         .withImportValues(store.toImportValues())\n                         .withStart(false)\n                         .build();\n            }\n\n            // Call _initialize if present (required by TinyGo -target wasm-unknown).\n            try {\n                ExportFunction initFn = instance.export(\"_initialize\");\n                if (Objects.nonNull(initFn)) {\n                    initFn.apply();\n                    LOG.debug(\"Called _initialize for {}\", wasmName);\n                }\n            } catch (com.dylibso.chicory.wasm.InvalidException e) {\n                LOG.debug(\"No _initialize export in {}\", wasmName);\n            }\n\n            if (Objects.isNull(instance.memory())) {\n                throw new ShenyuWasmInitException(\"memory not available in wasm file: \" + wasmName);\n            }\n        } catch (IOException e) {\n            throw new ShenyuWasmInitException(e);\n        }\n    }\n\n    private void registerWasiStubs(final Store store) {\n        // Use Chicory's built-in full WASI preview1 implementation for comprehensive\n        // WASI function coverage, matching the previous wasmtime-java behavior.\n        // Only inherit stdout/stderr so WASM guest output (e.g. Go println,\n        // Rust eprintln!) is visible for debugging. Avoid inheriting the full\n        // system context (env/args/filesystem) for security hardening.\n        var options = com.dylibso.chicory.wasi.WasiOptions.builder()\n                .withStdout(System.out)\n                .withStderr(System.err)\n                .build();\n        var wasi = com.dylibso.chicory.wasi.WasiPreview1.builder()\n                .withOptions(options)","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-plugin/shenyu-plugin-wasm-api/src/main/java/org/apache/shenyu/plugin/wasm/api/loader/WasmLoader.java#L132-L168","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// wat before\n(module (memory (export \"mem\") 1))\n// after\n(module (memory 1) (export \"memory\" (memory 0)))","handlingStrategy":"validation","validationCode":"// Build-time / pre-load check with wasm tooling\n// wasm-objdump -x module.wasm | grep -q 'memory' || echo 'ERROR: no memory export'","typeGuard":null,"tryCatchPattern":"try {\n    WasmLoader loader = new MyWasmPlugin();\n} catch (ShenyuWasmInitException e) {\n    if (e.getMessage().startsWith(\"memory not available\")) { /* rebuild wasm with exported memory */ }\n    throw e;\n}","preventionTips":["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."],"tags":["wasm","memory","initialization","incompatible-binary"],"backgroundTag":"wasm-missing-memory-export","analyzedSha":"567142e07261b3e615ae8850b30f4421f455cc5d","analyzedAt":"2026-09-12T10:08:21.293Z","contentChangedAt":"2026-09-12T10:08:21.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}