Skip to content

Commit

Permalink
remove unnecessary Option around request timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
yaahc committed Feb 19, 2021
1 parent 651d352 commit c372403
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
27 changes: 9 additions & 18 deletions zebra-network/src/peer/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ pub(super) enum State {
/// internal Response format.
tx: MustUseOneshotSender<Result<Response, SharedPeerError>>,
span: tracing::Span,
request_timer: Sleep,
},
}

Expand Down Expand Up @@ -403,15 +404,12 @@ impl State {
span,
mut tx,
mut handler,
request_timer,
} => {
// we have to get rid of the span reference so we can tamper with the state
let span = span.clone();
trace!(parent: &span, "awaiting response to client request");
let timer_ref = conn
.request_timer
.as_mut()
.expect("timeout must be set while awaiting response");
let cancel = future::select(timer_ref, tx.cancellation());
let cancel = future::select(request_timer, tx.cancellation());
match future::select(peer_rx.next(), cancel)
.instrument(span.clone())
.await
Expand Down Expand Up @@ -500,9 +498,12 @@ impl TryFrom<Transition> for State {
fn try_from(trans: Transition) -> Result<Self, Self::Error> {
match trans {
Transition::AwaitRequest => Ok(State::AwaitingRequest),
Transition::AwaitResponse { handler, tx, span } => {
Ok(State::AwaitingResponse { handler, tx, span })
}
Transition::AwaitResponse { handler, tx, span } => Ok(State::AwaitingResponse {
handler,
tx,
span,
request_timer: sleep(constants::REQUEST_TIMEOUT),
}),
Transition::ClientClose => Err(None),
Transition::Close(e) => Err(Some(e)),
Transition::CloseResponse { tx, e } => {
Expand All @@ -516,12 +517,6 @@ impl TryFrom<Transition> for State {
/// The state associated with a peer connection.
pub struct Connection<S, Tx> {
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,
/// A `mpsc::Receiver<ClientRequest>` that converts its results to
/// `InProgressClientRequest`
Expand Down Expand Up @@ -549,10 +544,6 @@ where
.step(&mut self, &mut peer_rx)
.await;

if matches!(transition, Transition::AwaitResponse { .. }) {
self.request_timer = Some(sleep(constants::REQUEST_TIMEOUT));
}

self.state = match transition.try_into() {
Ok(state) => Some(state),
Err(None) => {
Expand Down
1 change: 0 additions & 1 deletion zebra-network/src/peer/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,6 @@ where
svc: inbound_service,
client_rx: server_rx.into(),
peer_tx,
request_timer: None,
};

tokio::spawn(
Expand Down

0 comments on commit c372403

Please sign in to comment.