🚧 wip: finding a bug. It's in the udp_over_tcp code

When a TCP client disconnects, the rx loop gets confused and goes into an
infinite loop without ever yielding.
main
(on company time) 2022-12-20 14:40:51 -06:00
parent ce7a539413
commit 200c07da2f
5 changed files with 24 additions and 8 deletions

1
Cargo.lock generated
View File

@ -2418,6 +2418,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"tokio",
"tracing",
]
[[package]]

View File

@ -100,7 +100,7 @@ pub struct P4EndServer {
impl P4EndServer {
pub (crate) async fn connect (conf: Config) -> anyhow::Result <(Self, watch::Sender <bool>)> {
trace! ("P4 end server making its QUIC endpoint");
debug! ("P4 end server making its QUIC endpoint");
let endpoint = make_client_endpoint ("0.0.0.0:0".parse ()?, &[&conf.relay_cert])?;
let conf = if conf.use_udp_over_tcp {
@ -128,7 +128,7 @@ impl P4EndServer {
conf
};
trace! ("P4 end server connecting to P3 relay server");
debug! ("P4 end server connecting to P3 relay server");
let conn = protocol::p4_connect_to_p3 (
&endpoint,
conf.relay_addr,

View File

@ -257,7 +257,7 @@ pub async fn p4_connect_to_p3 (
bail! ("Server ID is longer than MAX_ID_LENGTH");
}
let new_conn = endpoint.connect (relay_addr, "localhost")?.await?;
let new_conn = endpoint.connect (relay_addr, "localhost")?.await.context ("UXTDVL2V quinn::Endpoint::connect")?;
let (mut send, mut recv) = new_conn.open_bi ().await?;
let cmd_type = Command::CONNECT_P4_TO_P3.0;
@ -265,7 +265,7 @@ pub async fn p4_connect_to_p3 (
send_lv_string (&mut send, server_id).await?;
expect_exact_response (&mut recv, [Command::OKAY.0, cmd_type, 0, 0]).await
.context ("P4 didn't get OK response when connecting to P3")?;
.context ("WMGW2RXU P4 didn't get OK response when connecting to P3")?;
Ok (new_conn)
}

View File

@ -6,5 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1.0.38"
tokio = { version = "1.8.1", features = ["full"] }
anyhow = "1.0.66"
tokio = { version = "1.23.0", features = ["full"] }
tracing = "0.1.37"

View File

@ -17,7 +17,12 @@ pub async fn rx (
udp_sock: Arc <UdpSocket>,
mut tcp_read: tcp::OwnedReadHalf,
) -> anyhow::Result <()> {
loop {
for i in 0u64.. {
// Optimizes down to a bitwise AND
if i % 8_192 == 0 {
tracing::trace! ("rx loop");
}
let mut tag = [0u8, 0, 0, 0];
let bytes_read = tcp_read.read (&mut tag).await?;
if bytes_read != 4 {
@ -47,6 +52,8 @@ pub async fn rx (
udp_sock.send (&buf).await?;
}
Ok (())
}
pub async fn tx (
@ -54,7 +61,12 @@ pub async fn tx (
mut tcp_write: tcp::OwnedWriteHalf,
) -> anyhow::Result <()>
{
loop {
for i in 0u64.. {
// Optimizes down to a bitwise AND
if i % 8_192 == 0 {
tracing::trace! ("tx loop");
}
let mut buf = vec! [0u8; 8_192];
let bytes_read = udp_sock.recv (&mut buf).await?;
buf.truncate (bytes_read);
@ -66,4 +78,6 @@ pub async fn tx (
tcp_write.write_all (&length).await?;
tcp_write.write_all (&buf).await?;
}
Ok (())
}