remove unnecessary Option around request timeout

This commit is contained in:
Jane Lusby 2021-02-18 14:33:06 -08:00 committed by Jane Lusby
parent 651d352ce1
commit c3724031df
2 changed files with 9 additions and 19 deletions

View File

@ -324,6 +324,7 @@ pub(super) enum State {
/// internal Response format. /// internal Response format.
tx: MustUseOneshotSender<Result<Response, SharedPeerError>>, tx: MustUseOneshotSender<Result<Response, SharedPeerError>>,
span: tracing::Span, span: tracing::Span,
request_timer: Sleep,
}, },
} }
@ -403,15 +404,12 @@ impl State {
span, span,
mut tx, mut tx,
mut handler, mut handler,
request_timer,
} => { } => {
// we have to get rid of the span reference so we can tamper with the state // we have to get rid of the span reference so we can tamper with the state
let span = span.clone(); let span = span.clone();
trace!(parent: &span, "awaiting response to client request"); trace!(parent: &span, "awaiting response to client request");
let timer_ref = conn let cancel = future::select(request_timer, tx.cancellation());
.request_timer
.as_mut()
.expect("timeout must be set while awaiting response");
let cancel = future::select(timer_ref, tx.cancellation());
match future::select(peer_rx.next(), cancel) match future::select(peer_rx.next(), cancel)
.instrument(span.clone()) .instrument(span.clone())
.await .await
@ -500,9 +498,12 @@ impl TryFrom<Transition> for State {
fn try_from(trans: Transition) -> Result<Self, Self::Error> { fn try_from(trans: Transition) -> Result<Self, Self::Error> {
match trans { match trans {
Transition::AwaitRequest => Ok(State::AwaitingRequest), Transition::AwaitRequest => Ok(State::AwaitingRequest),
Transition::AwaitResponse { handler, tx, span } => { Transition::AwaitResponse { handler, tx, span } => Ok(State::AwaitingResponse {
Ok(State::AwaitingResponse { handler, tx, span }) handler,
} tx,
span,
request_timer: sleep(constants::REQUEST_TIMEOUT),
}),
Transition::ClientClose => Err(None), Transition::ClientClose => Err(None),
Transition::Close(e) => Err(Some(e)), Transition::Close(e) => Err(Some(e)),
Transition::CloseResponse { tx, e } => { Transition::CloseResponse { tx, e } => {
@ -516,12 +517,6 @@ impl TryFrom<Transition> for State {
/// The state associated with a peer connection. /// The state associated with a peer connection.
pub struct Connection<S, Tx> { pub struct Connection<S, Tx> {
pub(super) state: Option<State>, pub(super) state: Option<State>,
/// A timeout for a client request. This is stored separately from
/// State so that we can move the future out of it independently of
/// other state handling.
// I don't think this is necessary, and will try moving it into `State` in
// the next commit TODO(jane)
pub(super) request_timer: Option<Sleep>,
pub(super) svc: S, pub(super) svc: S,
/// A `mpsc::Receiver<ClientRequest>` that converts its results to /// A `mpsc::Receiver<ClientRequest>` that converts its results to
/// `InProgressClientRequest` /// `InProgressClientRequest`
@ -549,10 +544,6 @@ where
.step(&mut self, &mut peer_rx) .step(&mut self, &mut peer_rx)
.await; .await;
if matches!(transition, Transition::AwaitResponse { .. }) {
self.request_timer = Some(sleep(constants::REQUEST_TIMEOUT));
}
self.state = match transition.try_into() { self.state = match transition.try_into() {
Ok(state) => Some(state), Ok(state) => Some(state),
Err(None) => { Err(None) => {

View File

@ -436,7 +436,6 @@ where
svc: inbound_service, svc: inbound_service,
client_rx: server_rx.into(), client_rx: server_rx.into(),
peer_tx, peer_tx,
request_timer: None,
}; };
tokio::spawn( tokio::spawn(