Skip to content

Commit

Permalink
Now graceful_shutdown close the connection after handshake is finished
Browse files Browse the repository at this point in the history
  • Loading branch information
ionut-slaveanu committed Aug 16, 2024
1 parent 4c84e8c commit 1977585
Showing 1 changed file with 8 additions and 11 deletions.
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

0 comments on commit 1977585

Please sign in to comment.