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

fix(runtime): incorrect min_timeout #246

Merged
merged 3 commits into from
May 1, 2024
Merged

Conversation

Mivik
Copy link
Contributor

@Mivik Mivik commented May 1, 2024

Currently the faulty implementation of min_timeout yields the greatest delay of current entries, which could cause misbehavior when multiple timers are used. For example:

#[compio::main]
async fn main() -> Result<()> {
    compio::runtime::spawn(async move {
        compio::time::sleep(std::time::Duration::from_secs(1)).await;
        println!("1s elapsed");
    })
    .detach();
    compio::time::sleep(Duration::from_secs(5)).await;
    println!("5s elapsed");

    Ok(())
}

This will hang for 5 seconds and prints two statements without specific order.

Simply reversing the order of TimeEntry fixes the problem. Also a unit test is added.

@George-Miao George-Miao self-requested a review May 1, 2024 16:08
@George-Miao George-Miao added bug Something isn't working package: runtime Related to compio-runtime labels May 1, 2024
@Berrysoft Berrysoft self-requested a review May 1, 2024 16:11
Berrysoft
Berrysoft previously approved these changes May 1, 2024
Copy link
Member

@Berrysoft Berrysoft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, but it seems that you are right.

@Berrysoft Berrysoft self-requested a review May 1, 2024 16:15
@Berrysoft Berrysoft dismissed their stale review May 1, 2024 16:16

Use Reverse instead.

Copy link
Member

@George-Miao George-Miao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@George-Miao George-Miao merged commit c0164a9 into compio-rs:master May 1, 2024
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working package: runtime Related to compio-runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants