matrix-org / matrix-org/rust-opa-wasm
Runtime error: memory types incompatible: expected memory limit for bundle evaluation
- Dominant language
- Rust
- Stars
- 80
- Forks
- 20
- PR merge metrics
- No merged PRs in 30d
Description
Hi, trying to integrate this with my application service and seeing this runtime error.
```
Error: incompatible import type for `env::memory`
Caused by:
memory types incompatible: expected memory limits (min: 3, max: none) doesn't match provided memory limits (min: 2, max: none)
```
This is the code:
```
use std::collections::HashMap;
use wasmtime::{Config, Engine, Module, Store};
use opa_wasm::Runtime;
use anyhow::Result;
#[tokio::main]
async fn main() -> Result<()> {
// Configure the WASM runtime
let mut config = Config::new();
config.async_support(true);
config.wasm_memory64(true); // Set minimum memory limit to 3 pages
let engine = Engine::new(&config)?;
// Load the policy WASM module
let module = opa_wasm::read_bundle("bundle.tar.gz").await?;
let module:Module = Module::new(&engine, module)?;
// Create a store which will hold the module instance
let mut store = Store::new(&engine, ());
let data = HashMap::from([("hello", "world")]);
let input = HashMap::from([("message", "world")]);
// Instantiate the module
let runtime = Runtime::new(&mut store, &module).await?;
let policy = runtime.with_data(&mut store, &data).await?;
// Evaluate the policy
let res: serde_json::Value = policy.evaluate(&mut store, "hello/world", &input).await?;
println!("{}", res);
Ok(())
}
```
Here is the cargo.toml:
```
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
env_logger = "0.10.1"
log = "0.4.20"
opa-wasm = { git = "https://github.com/matrix-org/rust-opa-wasm.git", branch = "main", features = ["loader","all-builtins","default"] }
tokio = { version = "1", features = ["full"] }
mini-redis = "0.4"
anyhow = "1.0.75"
serde_json = "1.0.108"
wasmtime = "14.0.4"
```
Requesting guidance on how to fix this. Tried a bunch of things around setting memory limits and nothing has resolved this so far.
Contributor guide
Research direction
Reproduce the failure with the provided main function and Cargo.toml, then inspect the Wasmtime configuration and the opa_wasm bundle's env::memory import requirements. Compare the configured engine and dependency versions with the module's declared memory limits; done means the bundle instantiates and policy.evaluate completes successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, wasm
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100