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

Windows sockets not waking in certain conditions #274

Open
EliseZeroTwo opened this issue Jul 18, 2024 · 5 comments
Open

Windows sockets not waking in certain conditions #274

EliseZeroTwo opened this issue Jul 18, 2024 · 5 comments

Comments

@EliseZeroTwo
Copy link

Version
List the versions of all monoio crates you are using. The easiest way to get
this information is using cargo tree subcommand: monoio v0.2.3

Platform
Windows 11 Pro 10.0.22631 Build 22631

Description
Enter your issue details here.
One way to structure the description:

When reading from a TCP socket using read, sometimes it just does not wake even though the socket has pending data.

I tried this code:

use std::{rc::Rc, sync::atomic::AtomicBool};
use monoio::{io::{AsyncReadRent, AsyncWriteRentExt}, net::{TcpListener, TcpStream}};

#[monoio::main]
async fn main() {
    let listener = TcpListener::bind("127.0.0.1:0").unwrap();
    let addr = listener.local_addr().unwrap();
    println!("Listening on {addr}");

    let (outgoing_res, incoming_res) = monoio::join!(TcpStream::connect_addr(addr), listener.accept());

    let mut outgoing = outgoing_res.unwrap();
    let (mut incoming, incoming_addr) = incoming_res.unwrap();

    println!("Connected to {addr} from {incoming_addr}");

    const TEXT: [&'static str; 0x10] = [
        "Meow 1",
        "Meow 2",
        "Meow 3",
        "Meow 4",
        "Meow 5",
        "Meow 6",
        "Meow 7",
        "Meow 8",
        "Meow 9",
        "Meow 10",
        "Meow 11",
        "Meow 12",
        "Meow 13",
        "Meow 14",
        "Meow 15",
        "Meow 16",
    ];

    let server_semaphore = Rc::new(AtomicBool::new(true));
    let client_semaphore = server_semaphore.clone();

    let client = monoio::spawn(async move {
        let mut recv_buf = Vec::<u8>::with_capacity(256);
        let mut r;
        let mut iter = 0;

        for text in TEXT {
            println!("Client writing");
            let written = outgoing.write_all(text).await.0.unwrap();
            println!("Client written {written} bytes\nClient reading");
            (r, recv_buf) = outgoing.read(recv_buf).await;
            println!("Client read {} bytes: {}", r.unwrap(), std::str::from_utf8(&recv_buf[..]).unwrap());
            recv_buf.clear();

            println!("Client finished iter {iter}");
            iter += 1;
        }
        client_semaphore.store(false, std::sync::atomic::Ordering::Relaxed);
    });

    let server = monoio::spawn(async move {
        let mut recv_buf = Vec::<u8>::with_capacity(256);
        let mut r;
        let mut iter = 0;

        while server_semaphore.load(std::sync::atomic::Ordering::Relaxed) {
            println!("Server reading");
            (r, recv_buf) = incoming.read(recv_buf).await;
            println!("Server read {}: {}\nServer echoing it back", r.unwrap(), std::str::from_utf8(&recv_buf[..]).unwrap());
            (r, recv_buf) = incoming.write_all(recv_buf).await;
            println!("Server wrote {} bytes", r.unwrap());
            recv_buf.clear();

            println!("Server finished iter {iter}");
            iter += 1;
        }
    });

    monoio::join!(server, client);
}

I expected to see this happen: All of the contents of the TEXT array to be sent over the socket and echoed back

Instead, this happened: The waker was never called even though there was data in the socket.

Listening on 127.0.0.1:49915
Connected to 127.0.0.1:49915 from 127.0.0.1:49916
Client writing
Client written 6 bytes
Client reading
Server reading
Server read 6: Meow 1
Server echoing it back
Server wrote 6 bytes
Server finished iter 0
Server reading
Client read 6 bytes: Meow 1
Client finished iter 0
Client writing
Client written 6 bytes
Client reading
@cafedetal
Copy link

+1

I'm also seeing this issue on windows, and it's a hard block on doing any proper networking since it makes it highly unreliable.

@geotro
Copy link

geotro commented Sep 5, 2024

I'm seeing this issue as well when trying to run a server I wrote using monoio on Windows

@ihciah
Copy link
Member

ihciah commented Sep 6, 2024

Windows support is still at early stage. @Lzzzzzt Do you have any idea about this issue?

@Lzzzzzt
Copy link
Collaborator

Lzzzzzt commented Sep 6, 2024

Windows support is still at early stage. @Lzzzzzt Do you have any idea about this issue?

Currently, I know almost nothing about Windows Socket, maybe I will investigate it after finishing my current work.

@cafedetal
Copy link

Appreciate the attention to the issue, if there's anymore that can be provided to help/test just let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants