From 785c8cc01605f9e160acdfee307630ab1c2b9c5b Mon Sep 17 00:00:00 2001 From: Artem Medvedev Date: Wed, 10 Apr 2024 19:33:56 +0200 Subject: [PATCH 1/2] fix: avoid unwrapping for the `Future` impl of `UpgradeableConnection` Closes #3621 --- src/server/conn/http1.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/server/conn/http1.rs b/src/server/conn/http1.rs index e3737edbae..a54274f40e 100644 --- a/src/server/conn/http1.rs +++ b/src/server/conn/http1.rs @@ -501,14 +501,18 @@ where type Output = crate::Result<()>; fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - match ready!(Pin::new(&mut self.inner.as_mut().unwrap().conn).poll(cx)) { - Ok(proto::Dispatched::Shutdown) => Poll::Ready(Ok(())), - Ok(proto::Dispatched::Upgrade(pending)) => { - let (io, buf, _) = self.inner.take().unwrap().conn.into_inner(); - pending.fulfill(Upgraded::new(io, buf)); - Poll::Ready(Ok(())) + if let Some(conn) = self.inner.as_mut() { + match ready!(Pin::new(&mut conn.conn).poll(cx)) { + Ok(proto::Dispatched::Shutdown) => Poll::Ready(Ok(())), + Ok(proto::Dispatched::Upgrade(pending)) => { + let (io, buf, _) = self.inner.take().unwrap().conn.into_inner(); + pending.fulfill(Upgraded::new(io, buf)); + Poll::Ready(Ok(())) + } + Err(e) => Poll::Ready(Err(e)), } - Err(e) => Poll::Ready(Err(e)), + } else { + Poll::Ready(Ok(())) } } } From 0558665f4c4ccfdb6d930990c6ab5f429d73695a Mon Sep 17 00:00:00 2001 From: Artem Medvedev Date: Wed, 10 Apr 2024 19:37:01 +0200 Subject: [PATCH 2/2] docs: add a comment --- src/server/conn/http1.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/server/conn/http1.rs b/src/server/conn/http1.rs index a54274f40e..5f07df1dfd 100644 --- a/src/server/conn/http1.rs +++ b/src/server/conn/http1.rs @@ -512,6 +512,7 @@ where Err(e) => Poll::Ready(Err(e)), } } else { + // inner is `None`, meaning the connection was upgraded, thus it's `Poll::Ready(Ok(()))` Poll::Ready(Ok(())) } }