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

Tokio 0.3 timer will hang when duration is small #3069

Closed
quininer opened this issue Oct 29, 2020 · 4 comments
Closed

Tokio 0.3 timer will hang when duration is small #3069

quininer opened this issue Oct 29, 2020 · 4 comments
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-time Module: tokio/time

Comments

@quininer
Copy link
Member

Version

└── tokio v0.3.2

Platform

Linux hostname 5.9.1-arch1-1 #1 SMP PREEMPT Sat, 17 Oct 2020 13:30:37 +0000 x86_64 GNU/Linux

and windows 10.

Description

code https://gist.github.com/quininer/72dd236419c67f99b1f9ae0711ca0411

fn main() {
    let rt = tokio::runtime::Runtime::new().unwrap();

    let j = rt.spawn(async move {
        loop {
            dbg!("start");
            tokio::time::sleep(std::time::Duration::from_millis(0)).await;
            dbg!("end");
        }
    });

    rt.block_on(j).unwrap();
}

This code may hang on sleep.

I discovered this problem earlier, but I haven't had time to debug it recently. :(

@quininer quininer added A-tokio Area: The main tokio crate C-bug Category: This is a bug. labels Oct 29, 2020
@Darksonn Darksonn added the M-time Module: tokio/time label Oct 29, 2020
@Darksonn
Copy link
Contributor

I changed it to the following:

fn main() {
    let rt = tokio::runtime::Runtime::new().unwrap();

    let j = rt.spawn(async move {
        let mut i = 0;
        loop {
            println!("start {}", i);
            tokio::time::sleep(std::time::Duration::from_millis(0)).await;
            println!("end {}", i);
            i += 1;
        }
    });

    rt.block_on(j).unwrap();
}

It behaves as I would expect, i.e. printing start and end forever. What do you see?

@quininer
Copy link
Member Author

It will always stop at a number on my machine. If you use tsan, it seems easier to reproduce.

Screenshot_20201029_205450

@carllerche
Copy link
Member

@bdonlan is working on timer improvements. He will include this as a test case. The PR should be up soon.

bdonlan pushed a commit to bdonlan/tokio that referenced this issue Oct 30, 2020
This is more-or-less a half-rewrite of the current time driver, supporting the
use of intrusive futures for timer registration.

Fixes: tokio-rs#3028, tokio-rs#3069
carllerche pushed a commit that referenced this issue Nov 23, 2020
More-or-less a half-rewrite of the current time driver, supporting the
use of intrusive futures for timer registration.

Fixes: #3028, #3069
@quininer
Copy link
Member Author

I think this has been fixed.

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

3 participants