Skip to content

wasmtime: list<u8> types do not work in async mode #141

@tailhook

Description

@tailhook

I'm using the following:

wit_bindgen_wasmtime::import!({
    paths: ["./wit/my_module.wit"],
    async: *,
});

And wit contains something along the lines of:

record response {
    body: string,
}
handle_request: function() -> response

This fails in runtime with the following:

thread 'tokio-runtime-worker' panicked at 'must use `call_async` with async stores', /work/target/.cargo/registry/src/github.zerozr99.workers.dev-1ecc6299db9ec823/wasmtime-0.33
.0/src/func/typed.rs:75:9
stack backtrace:
   0: std::panicking::begin_panic
             at /rustc/02072b482a8b5357f7fb5e5637444ae30e423c40/library/std/src/panicking.rs:525:12
   1: wasmtime::func::typed::TypedFunc<Params,Results>::call
             at ./target/.cargo/registry/src/github.zerozr99.workers.dev-1ecc6299db9ec823/wasmtime-0.33.0/src/func/typed.rs:75:9
   2: wit_bindgen_wasmtime::rt::copy_slice
             at ./target/.cargo/git/checkouts/wit-bindgen-f98ccff846621481/8fdf702/crates/wasmtime/src/lib.rs:154:9
   3: edgedb_wasm_server::abi::http_server_v1::edgedb_http_server_v1::EdgedbHttpServerV1<T>::handle_request::{{closure}}
             at ./server/src/abi/http_server_v1.rs:1:1

The issue is, copy_slice function which also accepts destructor:

    pub fn copy_slice<T: Endian>(
        store: impl AsContextMut,
        memory: &Memory,
        free: &TypedFunc<(i32, i32, i32), ()>,
        base: i32,
        len: i32,
        align: i32,
    ) -> Result<Vec<T>, Trap> {
        let size = (len as u32)
            .checked_mul(mem::size_of::<T>() as u32)
            .ok_or_else(|| Trap::new("array too large to fit in wasm memory"))?;
        let slice = memory
            .data(&store)
            .get(base as usize..)
            .and_then(|s| s.get(..size as usize))
            .ok_or_else(|| Trap::new("out of bounds read"))?;
        let result = Le::from_slice(slice).iter().map(|s| s.get()).collect();
        free.call(store, (base, size as i32, align))?;   // <<< this line should be async!
        Ok(result)
    }

Seems easy enough to fix. What fix do you prefer, having copy_slice_async function? Or just moving the free call out of the function into the generated code? (or maybe a boolean flag argument?).

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