Skip to content

Commit

Permalink
Improve logging for connection state errors
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 authored and dconnolly committed Jan 18, 2021
1 parent a6c1cd3 commit 4fe81da
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions zebra-network/src/peer/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,11 @@ where
State::AwaitingResponse {
ref mut handler, ..
} => span.in_scope(|| handler.process_message(peer_msg)),
_ => unreachable!(),
_ => unreachable!("unexpected state after AwaitingResponse: {:?}, peer_msg: {:?}, client_receiver: {:?}",
self.state,
peer_msg,
self.client_rx,
),
};
// If the message was not consumed, check whether it
// should be handled as a request.
Expand All @@ -444,7 +448,10 @@ where
State::AwaitingRequest
}
pending @ State::AwaitingResponse { .. } => pending,
_ => unreachable!(),
_ => unreachable!(
"unexpected failed connection state while AwaitingResponse: client_receiver: {:?}",
self.client_rx
),
};
}
}
Expand All @@ -465,7 +472,10 @@ where
let _ = tx.send(Err(e.into()));
State::AwaitingRequest
}
_ => unreachable!(),
_ => unreachable!(
"unexpected failed connection state while AwaitingResponse: client_receiver: {:?}",
self.client_rx
),
};
}
Either::Right((Either::Right(_), _peer_fut)) => {
Expand All @@ -481,7 +491,7 @@ where
Some(InProgressClientRequest { tx, span, .. }) => {
trace!(
parent: &span,
"erroring pending request to failed connection"
"sending an error response to a pending request on a failed connection"
);
let e = self
.error_slot
Expand All @@ -504,7 +514,10 @@ where
E: Into<SharedPeerError>,
{
let e = e.into();
debug!(%e, "failing peer service with error");
debug!(%e,
connection_state = ?self.state,
client_receiver = ?self.client_rx,
"failing peer service with error");
// Update the shared error slot
let mut guard = self
.error_slot
Expand Down Expand Up @@ -575,9 +588,17 @@ where

// These matches return a Result with (new_state, Option<Sender>) or an (error, Sender)
let new_state_result = match (&self.state, request) {
(Failed, _) => panic!("failed connection cannot handle requests"),
(AwaitingResponse { .. }, _) => panic!("tried to update pending request"),

(Failed, request) => panic!(
"failed connection cannot handle new request: {:?}, client_receiver: {:?}",
request,
self.client_rx
),
(pending @ AwaitingResponse { .. }, request) => panic!(
"tried to process new request: {:?} while awaiting a response: {:?}, client_receiver: {:?}",
request,
pending,
self.client_rx
),
(AwaitingRequest, Peers) => match self.peer_tx.send(Message::GetAddr).await {
Ok(()) => Ok((
AwaitingResponse {
Expand Down Expand Up @@ -875,7 +896,10 @@ where
self.fail_with(PeerError::Overloaded);
} else {
// We could send a reject to the remote peer.
error!(%e);
error!(%e,
connection_state = ?self.state,
client_receiver = ?self.client_rx,
"error processing peer request");
}
return;
}
Expand Down

0 comments on commit 4fe81da

Please sign in to comment.