From c11e1863639242070788c76a37399d9a3ffd92a2 Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Wed, 14 Dec 2022 14:02:48 -0500 Subject: [PATCH 1/2] server: Ignore `NotConnected` errors on shutdown Related to https://github.com/hyperium/tonic/issues/1183 --- src/proto/connection.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/proto/connection.rs b/src/proto/connection.rs index 59883cf3..582f989d 100644 --- a/src/proto/connection.rs +++ b/src/proto/connection.rs @@ -282,7 +282,13 @@ where State::Closing(reason, initiator) => { tracing::trace!("connection closing after flush"); // Flush/shutdown the codec - ready!(self.codec.shutdown(cx))?; + if let Err(e) = ready!(self.codec.shutdown(cx)) { + // If the error kind is NotConnected then ignore that + // since it means the connection is already shutdown. + if e.kind() != io::ErrorKind::NotConnected { + return Poll::Ready(Err(e.into())); + } + } // Transition the state to error self.inner.state = State::Closed(reason, initiator); From ebe537a92861b7383d7ba37dfc967a4caad847a2 Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Thu, 15 Dec 2022 09:51:16 -0500 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Eliza Weisman --- src/proto/connection.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/proto/connection.rs b/src/proto/connection.rs index 582f989d..4e4de994 100644 --- a/src/proto/connection.rs +++ b/src/proto/connection.rs @@ -283,11 +283,16 @@ where tracing::trace!("connection closing after flush"); // Flush/shutdown the codec if let Err(e) = ready!(self.codec.shutdown(cx)) { - // If the error kind is NotConnected then ignore that - // since it means the connection is already shutdown. + // If the error kind is NotConnected, ignore it, since + // it just means the connection is already shutdown. if e.kind() != io::ErrorKind::NotConnected { return Poll::Ready(Err(e.into())); - } + } else { + tracing::trace!( + "ignoring NotConnected error \ + (the connection has already closed)" + ); + } } // Transition the state to error