don't error on dropped connections

This commit is contained in:
soruh 2023-06-11 01:32:13 +02:00
parent 4cca315f61
commit b8afaba4ef

View File

@ -21,7 +21,7 @@ use tokio::{
sync::Mutex, sync::Mutex,
time::sleep, time::sleep,
}; };
use tracing::{error, info, instrument, warn, Level}; use tracing::{debug, error, info, instrument, warn, Level};
use tracing_subscriber::fmt::time::FormatTime; use tracing_subscriber::fmt::time::FormatTime;
use crate::packets::PacketKind; use crate::packets::PacketKind;
@ -247,7 +247,14 @@ async fn connection_handler(
let error = match res { let error = match res {
Err(_) => Some("internal server error".to_owned()), Err(_) => Some("internal server error".to_owned()),
Ok(Err(err)) => Some(err.to_string()), Ok(Err(err)) => match err.downcast_ref::<std::io::Error>() {
Some(io_error) if io_error.kind() == std::io::ErrorKind::UnexpectedEof => {
debug!(%addr, "Client dropped their connection");
// don't print an error on dropped connections
None
}
_ => Some(err.to_string()),
},
Ok(Ok(())) => None, Ok(Ok(())) => None,
}; };
@ -264,6 +271,7 @@ async fn connection_handler(
length: packet.data.len().try_into().unwrap(), // this will never fail, as we just truncated the vector length: packet.data.len().try_into().unwrap(), // this will never fail, as we just truncated the vector
}; };
// Attempt to notify the client of the failure
let (_, mut writer) = stream.split(); let (_, mut writer) = stream.split();
_ = packet.send(&mut writer).await; _ = packet.send(&mut writer).await;
} }