diff --git a/src/main.rs b/src/main.rs index 3136c5a..1af5b6c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,7 +21,7 @@ use tokio::{ sync::Mutex, time::sleep, }; -use tracing::{error, info, instrument, warn, Level}; +use tracing::{debug, error, info, instrument, warn, Level}; use tracing_subscriber::fmt::time::FormatTime; use crate::packets::PacketKind; @@ -247,7 +247,14 @@ async fn connection_handler( let error = match res { Err(_) => Some("internal server error".to_owned()), - Ok(Err(err)) => Some(err.to_string()), + Ok(Err(err)) => match err.downcast_ref::() { + 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, }; @@ -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 }; + // Attempt to notify the client of the failure let (_, mut writer) = stream.split(); _ = packet.send(&mut writer).await; }