-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
copy_bidirectional not return #4556
Comments
i dont know why sometime return but sometime not return. If this method cannot be used during the use of TcpStream as a parameter, make sure to return every time it is closed. Well I hope it's noted in the documentation, as there are tons of TCP network proxies that misuse this method. Or can you provide a new method to provide copy bidirectional function specifically for TcpStream. I think this is very useful. |
It should work with tcp streams, however it wont return until the stream is closed in both directions. Perhaps the stream was only closed in one of the two directions? |
im sure what Ive seen in the real environment is that both sides are closed, but it still doesn't return. |
@b23r0 can you try and reproduce this? |
This is a problem found in the production environment. At that time, the client had about 30 to 40 concurrent connections. I could not reproduce this problem through a single or multiple normal connection and close connection tests in the development environment. This may be an issue that requires a race condition to trigger. I need to try to simulate a large number of concurrent connections to test and reproduce the problem, but the current work may delay this plan. I may have time to do more work in about a week. In the meantime maybe you can do more testing. |
Currently I use select! instead of copy_bidirectional and the problem doesn't happen again. ...
rt.spawn( async move {
let mut buf1 = [0u8;1024];
let mut buf2 = [0u8;1024];
loop{
select!{
a = s.read(&mut buf1) => {
let size = match a{
Ok(p) => p,
Err(_) => break,
};
if size == 0 {
break;
}
match c.write_all(&buf1[..size]).await{
Ok(_) => {},
Err(_) => break,
};
},
b = c.read(&mut buf2) => {
let size = match b{
Ok(p) => p,
Err(_) => break,
};
if size == 0 {
break;
}
match s.write_all(&buf2[..size]).await{
Ok(_) => {},
Err(_) => break,
};
}
}
}
});
... |
Okay, so the difference between that and What I suspect that you're seeing is that one of the two sockets has been closed in both directions, but the other socket has not closed its write direction and isn't writing anything, so |
@b23r0 I got same issue here, any updates? |
In my case there is many https://github.com/tokio-rs/tokio/blob/master/tokio/src/net/tcp/stream.rs#L1306 Only close write, how can we shutdown both? |
use crate |
Version
1.17.0
Platform
Linux iZbp1cerzh0yyvcuxg4opsZ 5.4.0-77-generic #86-Ubuntu SMP Thu Jun 17 02:35:03 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Description
I use copy_bidirectional() to copy between two tcpstreams, but after running online for a period of time, I found that a large number of TCP connections from clients are in the CLOSE_WAIT state. Through observation, it is found that some clients call in asynchronous threads after closing the connection. The copy_bidirectional() still doesn't return.
similar code:
The text was updated successfully, but these errors were encountered: