Add some missing tracing spans (#4660)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
20850b4cb4
commit
6aea0fd9e8
|
|
@ -59,33 +59,32 @@ impl AddressBookUpdater {
|
||||||
let address_book = Arc::new(std::sync::Mutex::new(address_book));
|
let address_book = Arc::new(std::sync::Mutex::new(address_book));
|
||||||
|
|
||||||
let worker_address_book = address_book.clone();
|
let worker_address_book = address_book.clone();
|
||||||
let span = Span::current();
|
|
||||||
let worker = move || {
|
let worker = move || {
|
||||||
span.in_scope(|| {
|
info!("starting the address book updater");
|
||||||
info!("starting the address book updater");
|
|
||||||
|
|
||||||
while let Some(event) = worker_rx.blocking_recv() {
|
while let Some(event) = worker_rx.blocking_recv() {
|
||||||
trace!(?event, "got address book change");
|
trace!(?event, "got address book change");
|
||||||
|
|
||||||
// # Correctness
|
// # Correctness
|
||||||
//
|
//
|
||||||
// Briefly hold the address book threaded mutex, to update the
|
// Briefly hold the address book threaded mutex, to update the
|
||||||
// state for a single address.
|
// state for a single address.
|
||||||
worker_address_book
|
worker_address_book
|
||||||
.lock()
|
.lock()
|
||||||
.expect("mutex should be unpoisoned")
|
.expect("mutex should be unpoisoned")
|
||||||
.update(event);
|
.update(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
let error = Err(AllAddressBookUpdaterSendersClosed.into());
|
let error = Err(AllAddressBookUpdaterSendersClosed.into());
|
||||||
info!(?error, "stopping address book updater");
|
info!(?error, "stopping address book updater");
|
||||||
error
|
error
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Correctness: spawn address book accesses on a blocking thread,
|
// Correctness: spawn address book accesses on a blocking thread,
|
||||||
// to avoid deadlocks (see #1976)
|
// to avoid deadlocks (see #1976)
|
||||||
let address_book_updater_task_handle = tokio::task::spawn_blocking(worker);
|
let span = Span::current();
|
||||||
|
let address_book_updater_task_handle =
|
||||||
|
tokio::task::spawn_blocking(move || span.in_scope(worker));
|
||||||
|
|
||||||
(
|
(
|
||||||
address_book,
|
address_book,
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use chrono::Utc;
|
||||||
use futures::stream::{FuturesUnordered, StreamExt};
|
use futures::stream::{FuturesUnordered, StreamExt};
|
||||||
use tokio::time::{sleep_until, timeout, Instant};
|
use tokio::time::{sleep_until, timeout, Instant};
|
||||||
use tower::{Service, ServiceExt};
|
use tower::{Service, ServiceExt};
|
||||||
|
use tracing::Span;
|
||||||
|
|
||||||
use zebra_chain::serialization::DateTime32;
|
use zebra_chain::serialization::DateTime32;
|
||||||
|
|
||||||
|
|
@ -333,9 +334,12 @@ where
|
||||||
//
|
//
|
||||||
// Extend handles duplicate addresses internally.
|
// Extend handles duplicate addresses internally.
|
||||||
let address_book = self.address_book.clone();
|
let address_book = self.address_book.clone();
|
||||||
tokio::task::spawn_blocking(move || address_book.lock().unwrap().extend(addrs))
|
let span = Span::current();
|
||||||
.await
|
tokio::task::spawn_blocking(move || {
|
||||||
.expect("panic in new peers address book update task");
|
span.in_scope(|| address_book.lock().unwrap().extend(addrs))
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.expect("panic in new peers address book update task");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the next candidate for a connection attempt, if any are available.
|
/// Returns the next candidate for a connection attempt, if any are available.
|
||||||
|
|
@ -386,7 +390,8 @@ where
|
||||||
};
|
};
|
||||||
|
|
||||||
// Correctness: Spawn address book accesses on a blocking thread, to avoid deadlocks (see #1976).
|
// Correctness: Spawn address book accesses on a blocking thread, to avoid deadlocks (see #1976).
|
||||||
let next_peer = tokio::task::spawn_blocking(next_peer)
|
let span = Span::current();
|
||||||
|
let next_peer = tokio::task::spawn_blocking(move || span.in_scope(next_peer))
|
||||||
.await
|
.await
|
||||||
.expect("panic in next peer address book task")?;
|
.expect("panic in next peer address book task")?;
|
||||||
|
|
||||||
|
|
@ -406,9 +411,12 @@ where
|
||||||
// Spawn address book accesses on a blocking thread,
|
// Spawn address book accesses on a blocking thread,
|
||||||
// to avoid deadlocks (see #1976).
|
// to avoid deadlocks (see #1976).
|
||||||
let address_book = self.address_book.clone();
|
let address_book = self.address_book.clone();
|
||||||
tokio::task::spawn_blocking(move || address_book.lock().unwrap().update(addr))
|
let span = Span::current();
|
||||||
.await
|
tokio::task::spawn_blocking(move || {
|
||||||
.expect("panic in peer failure address book update task");
|
span.in_scope(|| address_book.lock().unwrap().update(addr))
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.expect("panic in peer failure address book update task");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue