From 74a0578cdbeec61e8cefcc18d6aff6246049e5d7 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Tue, 6 Dec 2022 15:07:35 +0100 Subject: [PATCH] ignore ENOTCONN error during closing state of Connection If the underlying socket is already closed during State::Closing, it is not an error to get `ENOTCONN` when calling shutdown, so ignore it. This can happen when a connection is local to the host and the kernel already has shutdown the socket. Signed-off-by: Dominik Csapak --- src/proto/connection.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/proto/connection.rs b/src/proto/connection.rs index cd011a1d5..b296609ee 100644 --- a/src/proto/connection.rs +++ b/src/proto/connection.rs @@ -282,7 +282,12 @@ where State::Closing(reason, initiator) => { tracing::trace!("connection closing after flush"); // Flush/shutdown the codec - ready!(self.codec.shutdown(cx))?; + if let Err(err) = ready!(self.codec.shutdown(cx)) { + // ignore ENOTCONN error on shutdown, already in desired state + if reason != Reason::NO_ERROR || err.kind() != io::ErrorKind::NotConnected { + return Poll::Ready(Err(err.into())); + } + } // Transition the state to error self.inner.state = State::Closed(reason, initiator);