compio-rs / compio

A thread-per-core Rust runtime with IOCP/io_uring/polling.
MIT License
420 stars 37 forks source link

fix(runtime): incorrect min_timeout #246

Closed Mivik closed 5 months ago

Mivik commented 5 months ago

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.