Skip to content

timeout doesn't work as expected #474

@kanarus

Description

@kanarus

I created a demo project: https://github.com/kanarus/test-compio-timeout. The core part of this is:

    for _ in 0..100 {
        let x = timeout!(
            std::time::Duration::from_secs(2),
            heavy_task(std::time::Duration::from_secs(3))
        ).await;
        
        let y = my_timeout(
            sleep!(std::time::Duration::from_secs(2)),
            heavy_task(std::time::Duration::from_secs(3))
        ).await;
        
        println!("{x:?}, {y:?}");
    }

This demo provides compio and monoio feature flag to easily switch runtimes, and

  • my_timeout is a custom, generic timeout implementation.
  • sleep! calls {compio or monoio}::time::sleep(~).await based on selected feature.
  • timeout! calls {compio or monoio}::time::timeout(~).await.ok() based on selected feature.

My environment

uname -a
Linux ThinkPad 6.8.0-79-generic #79~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 15 16:54:53 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Expected behavior (by cargo run --features monoio)

  • print None, None every 4 seconds ( 2 secs + 2 secs ).
None, None
None, None
None, None
None, None
None, None
None, None
None, None
None, None
None, None
None, None

compio behavior (by cargo run --features compio)

  • print lines in irregular interval.
  • printed content is flaky.
  • is cancellation or something buggy?
None, Some("done")
Some("done"), Some("done")
Some("done"), None
Some("done"), Some("done")
None, None
None, Some("done")
None, None
Some("done"), Some("done")
Some("done"), Some("done")
Some("done"), Some("done")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions