Skip to content

Commit

Permalink
debug log when early close is encountered
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Oct 7, 2022
1 parent db4bfb3 commit cfb28a2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
13 changes: 11 additions & 2 deletions comms/core/src/protocol/rpc/server/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,17 @@ pub enum RpcServerError {
ServiceCallExceededDeadline,
#[error("Stream read exceeded deadline")]
ReadStreamExceededDeadline,
#[error("Early close error: {0}")]
EarlyCloseError(#[from] EarlyCloseError<BytesMut>),
#[error("Early close: {0}")]
EarlyClose(#[from] EarlyCloseError<BytesMut>),
}

impl RpcServerError {
pub fn early_close_io(&self) -> Option<&io::Error> {
match self {
Self::EarlyClose(e) => e.io(),
_ => None,
}
}
}

impl From<oneshot::error::RecvError> for RpcServerError {
Expand Down
16 changes: 12 additions & 4 deletions comms/core/src/protocol/rpc/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use std::{
convert::TryFrom,
future::Future,
io,
io::ErrorKind,
pin::Pin,
sync::Arc,
task::Poll,
Expand Down Expand Up @@ -353,7 +354,7 @@ where
{
Ok(_) => {},
Err(err @ RpcServerError::HandshakeError(_)) => {
debug!(target: LOG_TARGET, "{}", err);
debug!(target: LOG_TARGET, "Handshake error: {}", err);
metrics::handshake_error_counter(&node_id, &notification.protocol).inc();
},
Err(err) => {
Expand Down Expand Up @@ -530,7 +531,7 @@ where
metrics::error_counter(&self.node_id, &self.protocol, &err).inc();
let level = match &err {
RpcServerError::Io(e) => err_to_log_level(e),
RpcServerError::EarlyCloseError(e) => e.io().map(err_to_log_level).unwrap_or(log::Level::Error),
RpcServerError::EarlyClose(e) => e.io().map(err_to_log_level).unwrap_or(log::Level::Error),
_ => log::Level::Error,
};
log!(
Expand Down Expand Up @@ -562,8 +563,10 @@ where
err,
);
}
error!(
let level = err.early_close_io().map(err_to_log_level).unwrap_or(log::Level::Error);
log!(
target: LOG_TARGET,
level,
"(peer: {}, protocol: {}) Failed to handle request: {}",
self.node_id,
self.protocol_name(),
Expand Down Expand Up @@ -880,8 +883,13 @@ fn into_response(request_id: u32, result: Result<BodyBytes, RpcStatus>) -> RpcRe
}

fn err_to_log_level(err: &io::Error) -> log::Level {
error!(target: LOG_TARGET, "KIND: {}", err.kind());
match err.kind() {
io::ErrorKind::BrokenPipe | io::ErrorKind::WriteZero => log::Level::Debug,
ErrorKind::ConnectionReset |
ErrorKind::ConnectionAborted |
ErrorKind::BrokenPipe |
ErrorKind::WriteZero |
ErrorKind::UnexpectedEof => log::Level::Debug,
_ => log::Level::Error,
}
}

0 comments on commit cfb28a2

Please sign in to comment.