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

Using timeout hangs a program on wasm32-wasip1 #7036

Open
surban opened this issue Dec 14, 2024 · 0 comments · May be fixed by #7041
Open

Using timeout hangs a program on wasm32-wasip1 #7036

surban opened this issue Dec 14, 2024 · 0 comments · May be fixed by #7041
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug.

Comments

@surban
Copy link
Contributor

surban commented Dec 14, 2024

Version

tokio-hang v0.1.0 (/data/surban/dev/rust-wasi-web/tokio-hang)
└── tokio v1.42.0 (/data/surban/dev/tokio/tokio)
    └── tokio-macros v2.4.0 (proc-macro) (/data/surban/dev/tokio/tokio-macros)

Platform
wasm32-wasip1 and wasm32-wasip1-threads
using wasmtime executor or wasmer

Description
Using the timeout function makes the following program hang on wasm32-wasip1.
The program works fine either on

  • target x86_64-unknown-linux-gnu
  • also on wasm32-wasip1 without the timeout wrapper

I tried this code:

Available at https://github.com/surban/tokio-hang

use std::time::Duration;

use futures::{SinkExt, StreamExt};
use tokio::time::timeout;

async fn send_task(mut tx: futures::channel::mpsc::Sender<u8>) {
    println!("feeding 0");
    tx.feed(0).await.unwrap();
    println!("flushing 0");
    tx.flush().await.unwrap();

    println!("feeding 1");
    tx.feed(1).await.unwrap();
    println!("flushing 1");
    tx.flush().await.unwrap();
}

async fn recv_task(mut rx: futures::channel::mpsc::Receiver<u8>) {
    loop {
        println!("waiting to receive");
        match rx.next().await {
            Some(msg) => println!("received: {msg}"),
            None => break,
        }
    }

    println!("end of receive");
}

#[tokio::main(flavor = "current_thread")]
async fn main() {
    let qlen = 0;
    let (a_tx, b_rx) = futures::channel::mpsc::channel::<u8>(qlen);

    let task = async move { tokio::join!(send_task(a_tx), recv_task(b_rx)) };
    timeout(Duration::from_secs(60), task).await.unwrap();

    // works without timeout:
    // task.await;
}

I expected to see the following output (it works on x86_64-unknown-linux-gnu):

feeding 0
flushing 0
waiting to receive
received: 0
waiting to receive
feeding 1
flushing 1
received: 1
waiting to receive
end of receive

Instead, this happened on wasm32-wasip1:

feeding 0
flushing 0
waiting to receive
received: 0
waiting to receive

Then it hangs.

@surban surban added A-tokio Area: The main tokio crate C-bug Category: This is a bug. labels Dec 14, 2024
@surban surban linked a pull request Dec 16, 2024 that will close this issue
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant