async-std icon indicating copy to clipboard operation
async-std copied to clipboard

async_std::net::TcpStream closes after write in it

Open mikstime opened this issue 5 years ago • 5 comments

System details

OS: MacOs Big Sur beta 5 CPU: 2,3 ghz 4cores intel i5 RAM 8GB 2133 MHz LPDDR3 Graphics Intel Iris Plus Graphics 655 1536 MB async-std: 1.6.3 Rust: 1.46

Report details

Connection is closed after attempting to write into TcpStream. I'm new to rust, so I can't dive in depth of language, but it's clearly a bug since I was unable to run correctly any of echo server examples. Examples based on std::net::TcpListener and std::net::TcpStream work correct with no errors. async_std::io::BufWriter makes no difference.

Example

fn main() -> std::io::Result<()> {
    async_std::task::block_on(async {
        use async_std::net::TcpListener;
        use async_std::prelude::*;

        let listener = TcpListener::bind("127.0.0.1:3000").await?;
        let mut incoming = listener.incoming();

         while let Some(stream) = incoming.next().await {
             let mut stream = stream?;
             println!("New connection");
             stream.write_all(b"hello world").await?; // Connection closes before sending a single byte
             // In this example server continue running.
         }
        Ok(())
    })
}

More details

I was able to read and write to local file with async_std::File. read and write methods for std::net::TcpStream works. async_std::io::copy(&mut r,&mut w).await?; works for File.

mikstime avatar Sep 10 '20 16:09 mikstime

Seeing that you run Big Sur, this may be an operating system behaviour? I cannot replicate this on windows and usually, tcpstreams should send all data before closing. This is partially behaviour provided by the operating system, though.

skade avatar Sep 28 '20 20:09 skade

I've recently updated to beta 6 and now it seems to work perfectly fine. But anyway this error looks strange to me since all other applications except Virtual Box has worked with no issue. And even more strange since sync version of stream is able to send all data.

I guess it's now solved since no one will be using macOS 11 beta 5 in future.

mikstime avatar Sep 30 '20 00:09 mikstime

@mikstime in this case, could you please monitor? We'll fix is this is in the release version.

skade avatar Oct 03 '20 12:10 skade

I'll do my best

mikstime avatar Oct 03 '20 13:10 mikstime

@mikstime Have you observed this issue again at any point since upgrading?

joshtriplett avatar Apr 27 '22 08:04 joshtriplett

I have not. I believe this issue could be closed for now.

mikstime avatar Nov 14 '22 08:11 mikstime