Skip to content

Commit cb3d4a5

Browse files
committed
fix possible infinite loop issue
1 parent c97c2dd commit cb3d4a5

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/server.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,8 +977,21 @@ impl Server {
977977
// this method is used as a select! branch, use while loop to write the data
978978
// instead of using write_all (which is not cancellation safe) to ensure
979979
// the code cancellation safe
980+
let mut wait_count = 0;
981+
let mut writen_count = 0;
980982
let mut written_bytes = 0;
981983
while written_bytes < n {
984+
if writen_count >= 10 {
985+
if wait_count < 3 {
986+
wait_count += 1;
987+
tokio::time::sleep(Duration::from_millis(2)).await;
988+
} else {
989+
error!("failed to write after having tried {writen_count} times, written {written_bytes}/{n}");
990+
return Err(ProxyError::InternalError);
991+
}
992+
}
993+
994+
writen_count += 1;
982995
written_bytes +=
983996
writer.write(&buffer[written_bytes..n]).await.map_err(|e| {
984997
error!("write failed: {e}");

0 commit comments

Comments
 (0)