rscarson / rustyscript

Effortless JS integration for rust
MIT License
168 stars 18 forks source link

Subsequent calls to `fetch` cause runtime to hang indefinitely #144

Closed Naxdy closed 2 months ago

Naxdy commented 3 months ago

Describe the bug Subsequent calls to fetch cause runtime to hang indefinitely

To Reproduce

let mut runtime = Runtime::new(RuntimeOptions {
    timeout: Duration::from_secs(5), // you can increase this to whatever you want
    ..Default::default()
})
.expect("Failed to create runtime");

let fetch_module = Module::new(
    "fetch_example.js",
    r#"
        export const getGoogle = async() => {
            return await fetch("https://google.com");
        };
    "#,
);

let module_handle = runtime
    .load_module(&fetch_module)
    .expect("Failed to load module");

let google_result: Value = runtime
    .call_function(&module_handle, "getGoogle", json_args!())
    .expect("Failed to call first function");

let google_result_second: Value = runtime
    .call_function(&module_handle, "getGoogle", json_args!())
    .expect("Failed to call second function");

Result: Test fails with:

Failed to call second function: Timeout("deadline has elapsed")

Expected behavior Both function calls succeed


If this is expected behavior, I suggest adding this info to the README, along with an explanation as to what causes this (if it is known).

rscarson commented 3 months ago

That's certainly a bug!

I've changed how the asynchronous runtime works in the background, I will check if this still occurs in the new version

Naxdy commented 3 months ago

Just tested myself on the latest master, and looks like this is not an issue anymore. Fixed in 0.5.0! :)

rscarson commented 3 months ago

Going to leave this open for tracking until 0.5.0 is published

rscarson commented 2 months ago

Fixed in 0.5.0