Skip to content

Timout setting does not seem to have any effect #392

Open

Description

@TimoLehnertz

Describe the bug
The timeout setting does not terminate long running scripts.

To Reproduce
Run the following code (its the example from the readme just simplified and with a long running loop added):

use rustyscript::{Module, Runtime, RuntimeOptions, Undefined, json_args};
use std::{error::Error, time::Duration};

fn main() -> Result<(), Box<dyn Error>> {
    let module = Module::new(
        "test.js",
        "
        for(let i = 0; i < 1000000000000; i++) {}
        ",
    );
    let mut runtime = Runtime::new(RuntimeOptions {
        timeout: Duration::from_millis(50),
        default_entrypoint: Some("load".to_string()),
        ..Default::default()
    })?;
    let module_handle = runtime.load_module(&module)?;
    runtime.call_entrypoint::<Undefined>(&module_handle, json_args!(2))?;
    Ok(())
}

The program runs for however long it takes to complete the loop. But shouldnt it be terminated after 50ms?

Expected behavior
Deno should be terminated after 50ms of runtime.

Additional context
Im running the currently lates version 0.12.3

Also: How should the timeout function in the first place? when the first call to runtime.call_entrypoint takes 40ms and then we call it again and it again takes 40ms. should that terminate deno or not?

Activity

  1. TimoLehnertz commented on Sep 7, 2025

    @TimoLehnertz
    Author

    For anybody coming across the same issue. Heres my workarround:
    When deno runs something like while(true) {} it never yields controll back to tokio. So the current thread is just toast forever. The only way ive found arround this is to have IsolateHandle to the v8 in another thread and to invoke terminate_execution() on that. That will stop the infinite loop and free the thread to handle the situation.
    The v8 handle can be obtained with rustyscript_runtime.deno_runtime().v8_isolate().thread_safe_handle().
    I came accross this by reading this thread: https://users.rust-lang.org/t/how-to-kill-a-thread/96422

  2. sbjoshi commented on Jan 7, 2026

    @sbjoshi

    @TimoLehnertz , I followed the thread you linked but didn't quite understand how to use it with RustyScript. Is is the case that one directly have to use v8 or deno? If you have, could you please share code snippet that works with RustyScript?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions