Log address metrics when the peer set has no ready peers
This commit is contained in:
parent
6a342e93ca
commit
5a30268d7a
|
@ -114,6 +114,7 @@ where
|
|||
demand_tx.clone(),
|
||||
handle_rx,
|
||||
inv_receiver,
|
||||
address_book.clone(),
|
||||
);
|
||||
let peer_set = Buffer::new(BoxService::new(peer_set), constants::PEERSET_BUFFER_SIZE);
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ use std::{
|
|||
future::Future,
|
||||
marker::PhantomData,
|
||||
pin::Pin,
|
||||
sync::{Arc, Mutex},
|
||||
task::{Context, Poll},
|
||||
time::Instant,
|
||||
};
|
||||
|
@ -29,7 +30,7 @@ use crate::{
|
|||
external::InventoryHash,
|
||||
internal::{Request, Response},
|
||||
},
|
||||
BoxError,
|
||||
AddressBook, BoxError,
|
||||
};
|
||||
|
||||
use super::{
|
||||
|
@ -102,6 +103,10 @@ where
|
|||
inventory_registry: InventoryRegistry,
|
||||
/// The last time we logged a message about the peer set size
|
||||
last_peer_log: Option<Instant>,
|
||||
/// A shared list of peer addresses.
|
||||
///
|
||||
/// Used for logging diagnostics.
|
||||
address_book: Arc<Mutex<AddressBook>>,
|
||||
}
|
||||
|
||||
impl<D> PeerSet<D>
|
||||
|
@ -119,6 +124,7 @@ where
|
|||
demand_signal: mpsc::Sender<()>,
|
||||
handle_rx: tokio::sync::oneshot::Receiver<Vec<JoinHandle<Result<(), BoxError>>>>,
|
||||
inv_stream: broadcast::Receiver<(InventoryHash, SocketAddr)>,
|
||||
address_book: Arc<Mutex<AddressBook>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
discover,
|
||||
|
@ -131,6 +137,7 @@ where
|
|||
handle_rx,
|
||||
inventory_registry: InventoryRegistry::new(inv_stream),
|
||||
last_peer_log: None,
|
||||
address_book,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -372,10 +379,16 @@ where
|
|||
}
|
||||
|
||||
self.last_peer_log = Some(Instant::now());
|
||||
// Only log address metrics in exceptional circumstances, to avoid lock contention.
|
||||
// TODO: replace with a watch channel that is updated in `AddressBook::update_metrics()`.
|
||||
let address_metrics = self.address_book.lock().unwrap().address_metrics();
|
||||
if unready_services_len == 0 {
|
||||
warn!("network request with no peer connections. Hint: check your network connection");
|
||||
warn!(
|
||||
?address_metrics,
|
||||
"network request with no peer connections. Hint: check your network connection"
|
||||
);
|
||||
} else {
|
||||
info!("network request with no ready peers: finding more peers, waiting for {} peers to answer requests",
|
||||
info!(?address_metrics, "network request with no ready peers: finding more peers, waiting for {} peers to answer requests",
|
||||
unready_services_len);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue