extism / extism

The framework for building with WebAssembly (wasm). Easily load wasm modules, move data, call functions, and build extensible apps.

Home Page:https://extism.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Regression: Can't cancel multiple calls for the same plugin instance

mhmd-azeez opened this issue · comments

Repro:

#[test]
fn test_cancel() {
    let f = Function::new(
        "hello_world",
        [ValType::I64],
        [ValType::I64],
        None,
        hello_world,
    );

    let mut plugin = Plugin::new(WASM_LOOP, [f], true).unwrap();
    let handle = plugin.cancel_handle();

    for _ in 0..3 {
        let h = handle.clone();
        let start = std::time::Instant::now();
        std::thread::spawn(move || {
            std::thread::sleep(std::time::Duration::from_secs(1));
            assert!(h.cancel().is_ok());
        });
        let _output: Result<&[u8], Error> = plugin.call("loop_forever", "abc123");
        let end = std::time::Instant::now();
        let time = end - start;
        println!("Cancelled plugin ran for {:?}", time);
    }
    // std::io::stdout().write_all(output).unwrap();
}

v1.0.0.0-rc0:

PS D:\dylibso\extism> cargo test tests::runtime::test_cancelt)
warning: some crates are on edition 2021 which defaults to `resolver = "2"`, but virtual workspaces default to `resolver = "1"`
note: to keep the current resolver, specify `workspace.resolver = "1"` in the workspace root's manifest
note: to use the edition 2021 resolver, specify `workspace.resolver = "2"` in the workspace root's manifest
warning: extism.c
   Compiling extism v1.0.0-alpha.0 (D:\dylibso\extism\runtime)
    Finished test [unoptimized + debuginfo] target(s) in 8.17s
     Running unittests src\lib.rs (target\debug\deps\extism-39ddf5b2be00d260.exe)

running 1 test
test tests::runtime::test_cancel ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 14 filtered out; finished in 0.44s

     Running unittests src\lib.rs (target\debug\deps\extism_convert-5547a723ee97e142.exe)

main:

PS D:\dylibso\extism> cargo test tests::runtime::test_cancel
warning: some crates are on edition 2021 which defaults to `resolver = "2"`, but virtual workspaces default to `resolver = "1"`
note: to keep the current resolver, specify `workspace.resolver = "1"` in the workspace root's manifest
note: to use the edition 2021 resolver, specify `workspace.resolver = "2"` in the workspace root's manifest
warning: extism.c
   Compiling extism v1.0.0-alpha.0 (D:\dylibso\extism\runtime)
    Finished test [unoptimized + debuginfo] target(s) in 14.74s
     Running unittests src\lib.rs (target\debug\deps\extism-0c8a588a906eb086.exe)

running 1 test
test tests::runtime::test_cancel has been running for over 60 seconds
PS D:\dylibso\extism>

Note: I had to stop the test process forcefully

I also tried to get a new handle for each cancellation:

#[test]
fn test_cancel() {
    let f = Function::new(
        "hello_world",
        [ValType::I64],
        [ValType::I64],
        UserData::default(),
        hello_world,
    );

    let mut plugin = Plugin::new(WASM_LOOP, [f], true).unwrap();
  
    for n in 0..3 {
        let handle = plugin.cancel_handle();

        let start = std::time::Instant::now();
        std::thread::spawn(move || {
            std::thread::sleep(std::time::Duration::from_secs(1));
            assert!(handle.cancel().is_ok());
        });
        let _output: Result<&[u8], Error> = plugin.call("loop_forever", "abc123");
        let end = std::time::Instant::now();
        let time = end - start;
        println!("Cancelled plugin ran for {:?}", time);
    }
    // std::io::stdout().write_all(output).unwrap();
}

this didn't fix the issue either