Skip to content

Commit

Permalink
Revert "Only reject pending client requests when the peer has errored"
Browse files Browse the repository at this point in the history
This reverts commit e06705e.
  • Loading branch information
teor2345 authored and yaahc committed Feb 24, 2021
1 parent 663ed6c commit 359015b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
40 changes: 16 additions & 24 deletions zebra-network/src/peer/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ impl State {
}
Either::Right((None, _)) => {
trace!("client_rx closed, ending connection");
Transition::ExitClient
Transition::Exit(PeerError::ConnectionDropped.into())
}
Either::Right((Some(req), _)) => {
if req.tx.is_canceled() {
Expand Down Expand Up @@ -439,32 +439,28 @@ enum Transition {
tx: MustUseOneshotSender<Result<Response, SharedPeerError>>,
span: tracing::Span,
},
/// Exiting because the client was closed or dropped, and there are
/// no more client requests.
ExitClient,
/// Exiting while awaiting further client requests
// Exiting while no client response is expected
Exit(SharedPeerError),
/// Exiting while processing a peer response to a client request
// Exiting while processing a client response
ExitResponse {
tx: MustUseOneshotSender<Result<Response, SharedPeerError>>,
e: SharedPeerError,
},
}

impl TryFrom<Transition> for State {
type Error = Option<SharedPeerError>;
type Error = SharedPeerError;

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::ExitClient => Err(None),
Transition::Exit(e) => Err(Some(e)),
Transition::Exit(e) => Err(e),
Transition::ExitResponse { tx, e } => {
let _ = tx.send(Err(e.clone()));
Err(Some(e))
Err(e)
}
}
}
Expand Down Expand Up @@ -529,20 +525,16 @@ where

self.state = match transition.try_into() {
Ok(state) => Some(state),
Err(None) => {
trace!("client_rx dropped: no pending client requests");
return;
}
Err(Some(e)) => {
while let Some(InProgressClientRequest { tx, span, .. }) =
self.client_rx.next().await
{
trace!(
parent: &span,
"sending an error response to a pending client request on a failed connection"
);
let _ = tx.send(Err(e.clone()));
}
Err(e) => {
// while let Some(InProgressClientRequest { tx, span, .. }) =
// self.client_rx.next().await
// {
// trace!(
// parent: &span,
// "sending an error response to a pending request on a failed connection"
// );
// let _ = tx.send(Err(e.clone()));
// }
return;
}
}
Expand Down
3 changes: 3 additions & 0 deletions zebra-network/src/peer/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ pub enum PeerError {
/// The remote peer closed the connection.
#[error("Peer closed connection")]
ConnectionClosed,
/// The local client closed the connection.
#[error("Internal client dropped connection")]
ConnectionDropped,
/// The remote peer did not respond to a [`peer::Client`] request in time.
#[error("Client request timed out")]
ClientRequestTimeout,
Expand Down

0 comments on commit 359015b

Please sign in to comment.