Skip to content

Runtime error: memory types incompatible: expected memory limit for bundle evaluation #161

Open
@unullmass

Description

@unullmass

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions