Revert "remove unnecessary Option around request timeout"
This reverts commit c3724031df.
This commit is contained in:
parent
e06120cd36
commit
fc44a97925
|
|
@ -324,7 +324,6 @@ 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,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -404,12 +403,15 @@ 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 cancel = future::select(request_timer, tx.cancellation());
|
let timer_ref = conn
|
||||||
|
.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
|
||||||
|
|
@ -498,12 +500,9 @@ 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 } => Ok(State::AwaitingResponse {
|
Transition::AwaitResponse { handler, tx, span } => {
|
||||||
handler,
|
Ok(State::AwaitingResponse { handler, tx, span })
|
||||||
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 } => {
|
||||||
|
|
@ -517,6 +516,12 @@ 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`
|
||||||
|
|
@ -544,6 +549,10 @@ 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) => {
|
||||||
|
|
|
||||||
|
|
@ -436,6 +436,7 @@ 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(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue