Skip to content

Commit

Permalink
fix: busy loop on shutdown (#834)
Browse files Browse the repository at this point in the history
When in a slow shutdown, this was busy looping since no more streams were left. The change here now only makes sure we poll one extra time if the state changed during the poll.

Fixes #831
  • Loading branch information
seanmonstar authored Jan 20, 2025
1 parent b109803 commit 8dc26ad
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1437,8 +1437,14 @@ where

fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
self.inner.maybe_close_connection_if_no_streams();
let had_streams_or_refs = self.inner.has_streams_or_other_references();
let result = self.inner.poll(cx).map_err(Into::into);
if result.is_pending() && !self.inner.has_streams_or_other_references() {
// if we had streams/refs, and don't anymore, wake up one more time to
// ensure proper shutdown
if result.is_pending()
&& had_streams_or_refs
&& !self.inner.has_streams_or_other_references()
{
tracing::trace!("last stream closed during poll, wake again");
cx.waker().wake_by_ref();
}
Expand Down

0 comments on commit 8dc26ad

Please sign in to comment.