Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide error logs when peer shut's down for us #1144

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ where
let downstream_to_upstream = async {
let res = copy_buf(&mut rd, &mut wu, stats, false).await;
trace!(?res, "send");
wu.shutdown().await?;
ignore_shutdown_errors(wu.shutdown().await)?;
res
};

let upstream_to_downstream = async {
let res = copy_buf(&mut ru, &mut wd, stats, true).await;
trace!(?res, "receive");
wd.shutdown().await?;
ignore_shutdown_errors(wd.shutdown().await)?;
res
};

Expand All @@ -107,6 +107,21 @@ where
Ok(())
}

// During shutdown, the other end may have already disconnected. That is fine, they shutdown for us.
// Ignore it.
fn ignore_shutdown_errors(res: Result<(), io::Error>) -> Result<(), io::Error> {
match &res {
Err(e)
if e.kind() == io::ErrorKind::NotConnected
|| e.kind() == io::ErrorKind::UnexpectedEof =>
{
trace!(err=%e, "failed to shutdown peer, they already shutdown");
Ok(())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we still get a trace in this case? Should probably still be able to see this is being ignored @ trace level.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea; done

}
_ => res,
}
}

// CopyBuf is a fork of Tokio's same struct, with additional support for resizing and metrics reporting.
#[must_use = "futures do nothing unless you `.await` or poll them"]
struct CopyBuf<'a, R: ?Sized, W: ?Sized> {
Expand Down