From 8c9d6f32b972a3c3882a304f8e5156034805ed43 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Sat, 10 Feb 2024 10:37:56 +0100 Subject: [PATCH] Ignore NotConnected error in poll_shutdown() We try to write buffered data to the stream before shutting it down. This seems to be in line with the guidance from Tokio's AsyncWrite docs: > Invocation of a shutdown implies an invocation of flush. Once this method > returns `Ready` it implies that a flush successfully happened before the > shutdown happened. That is, callers don't need to call flush before > calling shutdown. They can rely that by calling shutdown any pending > buffered data will be written out. We propagate errors from the write. However, if we get a `NotConnected` error during shutdown we might just as well ignore it. --- src/common/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/common/mod.rs b/src/common/mod.rs index 664f8f93..497be56c 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -333,7 +333,11 @@ where fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { while self.session.wants_write() { - ready!(self.write_io(cx))?; + match ready!(self.write_io(cx)) { + Ok(_) => {} + Err(err) if err.kind() == io::ErrorKind::NotConnected => {} + Err(err) => return Poll::Ready(Err(err)), + } } Pin::new(&mut self.io).poll_shutdown(cx) }