diff --git a/src/proto/connection.rs b/src/proto/connection.rs index 59883cf3..4e4de994 100644 --- a/src/proto/connection.rs +++ b/src/proto/connection.rs @@ -282,7 +282,18 @@ 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, 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 self.inner.state = State::Closed(reason, initiator);