add wait in rejector to accomodate bad TCP stacks in itelex devices

This commit is contained in:
soruh 2023-09-03 13:28:58 +02:00
parent 7ba68cedbd
commit 4ad5504004
2 changed files with 16 additions and 4 deletions

View File

@ -303,7 +303,7 @@ async fn connection_handler(
}
}
sleep(Duration::from_secs(3)).await;
sleep(Duration::from_secs(2)).await;
_ = stream.shutdown().await;
}

View File

@ -12,10 +12,11 @@ use std::{
use eyre::eyre;
use serde::{Deserialize, Serialize, Serializer};
use tokio::{
io::AsyncWriteExt,
net::TcpListener,
sync::{watch::Receiver, Mutex},
task::JoinHandle,
time::Instant,
time::{sleep, Instant},
};
use tracing::{debug, error, info, instrument, warn};
@ -353,12 +354,23 @@ impl Rejector {
spawn(&format!("rejector for port {port}",), async move {
let (listener, packet) = state.as_ref();
let packet = Arc::new(packet.clone());
let listener = listener.lock().await;
loop {
if let Ok((mut socket, _)) = listener.accept().await {
let (_, mut writer) = socket.split();
_ = packet.send(&mut writer).await;
let packet = packet.clone();
tokio::task::spawn(async move {
// todo: if a client is very slow this blocks the accept loop...
let (_, mut writer) = socket.split();
_ = packet.send(&mut writer).await;
// wait two seconds before closing the connection
// to accomodate bad itelex tpc stacks
sleep(Duration::from_secs(2)).await;
_ = socket.shutdown().await;
});
}
}
})