Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change graceful_shutdown function behavior. #3729

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions src/proto/h2/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pin_project! {
service: S,
state: State<T, B>,
date_header: bool,
close_pending: bool
}
}

Expand All @@ -101,7 +102,6 @@ where
hs: Handshake<Compat<T>, SendBuf<B::Data>>,
},
Serving(Serving<T, B>),
Closed,
}

struct Serving<T, B>
Expand Down Expand Up @@ -172,26 +172,24 @@ where
},
service,
date_header: config.date_header,
close_pending: false,
}
}

pub(crate) fn graceful_shutdown(&mut self) {
trace!("graceful_shutdown");
match self.state {
State::Handshaking { .. } => {
// fall-through, to replace state with Closed
self.close_pending = true;
return;
}
State::Serving(ref mut srv) => {
if srv.closing.is_none() {
srv.conn.graceful_shutdown();
}
return;
}
State::Closed => {
return;
}
}
self.state = State::Closed;
}
}

Expand Down Expand Up @@ -228,12 +226,11 @@ where
})
}
State::Serving(ref mut srv) => {
ready!(srv.poll_server(cx, &mut me.service, &mut me.exec))?;
return Poll::Ready(Ok(Dispatched::Shutdown));
}
State::Closed => {
// graceful_shutdown was called before handshaking finished,
// nothing to do here...
if true == me.close_pending && srv.closing.is_none() {
srv.conn.graceful_shutdown();
}
ready!(srv.poll_server(cx, &mut me.service, &mut me.exec))?;
return Poll::Ready(Ok(Dispatched::Shutdown));
}
};
Expand Down