Skip to content

Commit

Permalink
Ignore NotConnected error in poll_shutdown()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
djc committed Feb 10, 2024
1 parent ff32e1e commit 8c9d6f3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,11 @@ where

fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
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)
}
Expand Down

0 comments on commit 8c9d6f3

Please sign in to comment.