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

TcpStream read task does not return although data is available #1063

Open
musli83 opened this issue Aug 11, 2023 · 0 comments
Open

TcpStream read task does not return although data is available #1063

musli83 opened this issue Aug 11, 2023 · 0 comments

Comments

@musli83
Copy link

musli83 commented Aug 11, 2023

Hi I have a strange bug that I am debugging for a few days now.

I am using async-std::net::TcpStream as part of a larger program like this:

// init socket and connection
let socket = std::net::SocketAddrV4::new(addr, port);
let stream = async_std::net::TcpStream::connect(socket).await?;

// get writer and reader
let mut reader = stream.clone();
let mut writer = stream;

// spawn writter
async_std::task::spawn(async move {
            Self::start_writer(&mut writer, cmd_rx, username, password, price_modify).await
        });

// set buffer
let mut buffer = bytes::BytesMut::with_capacity(8*1024);


// in loop read data and process it
 loop {
     println!("Read start");
     let n = reader.read(&mut buffer).await?;
    println!("Read end");

    // do stuff with data
}

This code worked fine for months for multiple connections but now I am connecting to new server and it stops randomly after few seconds to minutes. Always hangs on the read call. - I get "Read start" printout but no "Read end".

When I check what is happening in wireshark I can see packets coming in and TCP receive window starts decreasing until zero window is reached.

Must be something timing related as if I add to much debug printouts it works for longer time or even doesn't halt at all

When I change code so I use std::net::TcpStream instead of async-std::net::TcpStream everything works fine.

Difference between new and old connections is that new one is direct connection to NY server from London. Previous ones go through local repeater in London. Otherwise type of data and connection is the same.

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

1 participant