Open
Description
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
Metadata
Metadata
Assignees
Labels
No labels