Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time not advancing with spawn_blocking from a LocalSet #6242

Closed
mcches opened this issue Dec 22, 2023 · 2 comments
Closed

Time not advancing with spawn_blocking from a LocalSet #6242

mcches opened this issue Dec 22, 2023 · 2 comments
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-time Module: tokio/time

Comments

@mcches
Copy link

mcches commented Dec 22, 2023

Version
List the versions of all tokio crates you are using. The easiest way to get
this information is using cargo tree subcommand:

cargo tree | grep tokio

tokio = { version = "1", features = ["full"] }

Platform
The output of uname -a (UNIX), or version and 32 or 64-bit (Windows)

uname -a
Darwin 6c7e67b9eeac 22.6.0 Darwin Kernel Version 22.6.0: Thu Nov  2 07:43:25 PDT 2023; root:xnu-8796.141.3.701.17~6/RELEASE_ARM64_T6020 arm64

Description
Enter your issue details here.
One way to structure the description:

Time does not advance with a paused runtime when a spawn_blocking task is running (or blocking).

This seems related to: #5115

I tried this code:

#[test]
fn spawn_blocking() {
    let rt = tokio::runtime::Builder::new_current_thread()
        .enable_time()
        .start_paused(true)
        .build()
        .unwrap();

    let _g = rt.enter();

    let ls = tokio::task::LocalSet::new();
    ls.spawn_local(async {
        tokio::task::spawn_blocking(|| {
            println!("{:?}: parking...", std::thread::current().name());
            std::thread::park()
        });
    });

    rt.block_on(async {
        println!("{:?}: run_until for 10ms", std::thread::current().name());
        ls.run_until(tokio::time::sleep(Duration::from_millis(10)))
            .await;

        println!("run_until done");
    });
}

I expected to see this happen: I'd expect the run_until to complete, albeit instantaneously,

Instead, this happened: "run_until done" never emits

@mcches mcches added A-tokio Area: The main tokio crate C-bug Category: This is a bug. labels Dec 22, 2023
@Darksonn Darksonn added the M-time Module: tokio/time label Dec 22, 2023
@Darksonn
Copy link
Contributor

It's because time is paused. Time does not advance if there are any spawn_blocking tasks.

@Darksonn
Copy link
Contributor

Darksonn commented Jan 1, 2024

Closing as working-as-intended.

@Darksonn Darksonn closed this as not planned Won't fix, can't repro, duplicate, stale Jan 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-time Module: tokio/time
Projects
None yet
Development

No branches or pull requests

2 participants