Improve logging for initial peer connections (#2896)

Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com>
This commit is contained in:
teor 2021-10-19 04:43:12 +10:00 committed by GitHub
parent 42ce79aad9
commit c8ad19080a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 4 deletions

View File

@ -87,6 +87,15 @@ pub(super) struct MustUseOneshotSender<T: std::fmt::Debug> {
pub tx: Option<oneshot::Sender<T>>,
}
impl std::fmt::Debug for Client {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// skip the channels, they don't tell us anything useful
f.debug_struct("Client")
.field("error_slot", &self.error_slot)
.finish()
}
}
impl From<ClientRequest> for InProgressClientRequest {
fn from(client_request: ClientRequest) -> Self {
let ClientRequest { request, tx, span } = client_request;

View File

@ -74,6 +74,16 @@ pub enum PeerError {
#[derive(Default, Clone)]
pub(super) struct ErrorSlot(Arc<std::sync::Mutex<Option<SharedPeerError>>>);
impl std::fmt::Debug for ErrorSlot {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// don't hang if the mutex is locked
// show the panic if the mutex was poisoned
f.debug_struct("ErrorSlot")
.field("error", &self.0.try_lock())
.finish()
}
}
impl ErrorSlot {
/// Read the current error in the slot.
///

View File

@ -195,7 +195,16 @@ where
S: Service<SocketAddr, Response = Change<SocketAddr, peer::Client>, Error = BoxError> + Clone,
S::Future: Send + 'static,
{
info!(?initial_peers, "connecting to initial peer set");
let initial_peer_count = initial_peers.len();
let mut handshake_success_total: usize = 0;
let mut handshake_error_total: usize = 0;
info!(
?initial_peer_count,
?initial_peers,
"connecting to initial peer set"
);
// # Security
//
// TODO: rate-limit initial seed peer connections (#2326)
@ -217,13 +226,38 @@ where
.collect();
while let Some(handshake_result) = handshakes.next().await {
// this is verbose, but it's better than just hanging with no output
if let Err((addr, ref e)) = handshake_result {
info!(?addr, ?e, "an initial peer connection failed");
match handshake_result {
Ok(ref change) => {
handshake_success_total += 1;
debug!(
?handshake_success_total,
?handshake_error_total,
?change,
"an initial peer handshake succeeded"
);
}
Err((addr, ref e)) => {
// this is verbose, but it's better than just hanging with no output when there are errors
handshake_error_total += 1;
info!(
?handshake_success_total,
?handshake_error_total,
?addr,
?e,
"an initial peer connection failed"
);
}
}
tx.send(handshake_result.map_err(|(_addr, e)| e)).await?;
}
info!(
?handshake_success_total,
?handshake_error_total,
"finished connecting to initial seed peers"
);
Ok(())
}