diff --git a/src/client.rs b/src/client.rs index cb7e677a..a1a9a781 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1468,8 +1468,12 @@ where type Output = Result<(), crate::Error>; fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - self.inner.maybe_close_connection_if_no_streams(); + // Snapshot before checking for shutdown: the last reference may be + // dropped after the shutdown check, before inner.poll registers a + // waker. A snapshot taken after that drop would be false and skip the + // self-wake below, leaving the connection pending without closing. let had_streams_or_refs = self.inner.has_streams_or_other_references(); + self.inner.maybe_close_connection_if_no_streams(); let result = self.inner.poll(cx).map_err(Into::into); // if we had streams/refs, and don't anymore, wake up one more time to // ensure proper shutdown