From 6e17c3a6c7d256953433de172accaa0d135842cc Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 25 Feb 2025 14:47:01 +0100 Subject: [PATCH] Attempt to fix loop --- src/main.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 88ca55f..6db70b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -117,7 +117,9 @@ async fn main() -> Result<(), Box> { log::info!("Got a new client read {count}"); if count == 0 { - log::warn!("infinite loop"); + log::warn!("infinite loop (client)"); + drop(client_write); + drop(upstream); return; } @@ -135,10 +137,21 @@ async fn main() -> Result<(), Box> { } count = upstream.read(&mut buf_server) => { - let count = match count{ Ok(count) => count,Err(e) => { - log::error!("Failed to read from upstream! {e}"); + let count = match count { + Ok(count) => count, + Err(e) => { + log::error!("Failed to read from upstream! {e}"); + return; + } + }; + + if count == 0 { + log::warn!("infinite loop (upstream)"); + drop(client_write); + drop(upstream); return; - }}; + } + log::info!("Got a new upstream read {count}"); client_write.write_all(&buf_server[..count]).await.expect("Failed to write to client"); res_file.write_all(&buf_server[..count]).expect("Failed to write to res");