Skip to content

Commit

Permalink
Add some missing tracing spans (#4660)
Browse files Browse the repository at this point in the history
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
teor2345 and mergify[bot] authored Jun 23, 2022
1 parent 20850b4 commit 6aea0fd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
37 changes: 18 additions & 19 deletions zebra-network/src/address_book_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,33 +59,32 @@ impl AddressBookUpdater {
let address_book = Arc::new(std::sync::Mutex::new(address_book));

let worker_address_book = address_book.clone();
let span = Span::current();
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() {
trace!(?event, "got address book change");
while let Some(event) = worker_rx.blocking_recv() {
trace!(?event, "got address book change");

// # Correctness
//
// Briefly hold the address book threaded mutex, to update the
// state for a single address.
worker_address_book
.lock()
.expect("mutex should be unpoisoned")
.update(event);
}
// # Correctness
//
// Briefly hold the address book threaded mutex, to update the
// state for a single address.
worker_address_book
.lock()
.expect("mutex should be unpoisoned")
.update(event);
}

let error = Err(AllAddressBookUpdaterSendersClosed.into());
info!(?error, "stopping address book updater");
error
})
let error = Err(AllAddressBookUpdaterSendersClosed.into());
info!(?error, "stopping address book updater");
error
};

// Correctness: spawn address book accesses on a blocking thread,
// 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,
Expand Down
22 changes: 15 additions & 7 deletions zebra-network/src/peer_set/candidate_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use chrono::Utc;
use futures::stream::{FuturesUnordered, StreamExt};
use tokio::time::{sleep_until, timeout, Instant};
use tower::{Service, ServiceExt};
use tracing::Span;

use zebra_chain::serialization::DateTime32;

Expand Down Expand Up @@ -333,9 +334,12 @@ where
//
// Extend handles duplicate addresses internally.
let address_book = self.address_book.clone();
tokio::task::spawn_blocking(move || address_book.lock().unwrap().extend(addrs))
.await
.expect("panic in new peers address book update task");
let span = Span::current();
tokio::task::spawn_blocking(move || {
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.
Expand Down Expand Up @@ -386,7 +390,8 @@ where
};

// 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
.expect("panic in next peer address book task")?;

Expand All @@ -406,9 +411,12 @@ where
// Spawn address book accesses on a blocking thread,
// to avoid deadlocks (see #1976).
let address_book = self.address_book.clone();
tokio::task::spawn_blocking(move || address_book.lock().unwrap().update(addr))
.await
.expect("panic in peer failure address book update task");
let span = Span::current();
tokio::task::spawn_blocking(move || {
span.in_scope(|| address_book.lock().unwrap().update(addr))
})
.await
.expect("panic in peer failure address book update task");
}
}

Expand Down

0 comments on commit 6aea0fd

Please sign in to comment.