From f8e26347a0ff3aa48f9425f285c08c047a043e39 Mon Sep 17 00:00:00 2001 From: teor Date: Wed, 28 Jun 2023 05:42:04 +1000 Subject: [PATCH] Log a zebra-network task cancel on shutdown, rather than panicking (#7078) --- zebra-network/src/peer_set/initialize.rs | 27 +++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/zebra-network/src/peer_set/initialize.rs b/zebra-network/src/peer_set/initialize.rs index 14f2ba5c..cdd4807e 100644 --- a/zebra-network/src/peer_set/initialize.rs +++ b/zebra-network/src/peer_set/initialize.rs @@ -1138,12 +1138,29 @@ async fn report_failed(address_book: Arc>, addr: M // # Correctness // - // Spawn address book accesses on a blocking thread, - // to avoid deadlocks (see #1976). + // Spawn address book accesses on a blocking thread, to avoid deadlocks (see #1976). let span = Span::current(); - tokio::task::spawn_blocking(move || { + let task_result = tokio::task::spawn_blocking(move || { span.in_scope(|| address_book.lock().unwrap().update(addr)) }) - .await - .expect("panic in peer failure address book update task"); + .await; + + match task_result { + Ok(updated_addr) => assert_eq!( + updated_addr.map(|addr| addr.addr()), + Some(addr.addr()), + "incorrect address updated by address book: \ + original: {addr:?}, updated: {updated_addr:?}" + ), + Err(e @ JoinError { .. }) => { + if e.is_panic() { + panic!("panic in peer failure address book update task: {e:?}"); + } else { + info!( + "task error during peer failure address book update task: {e:?},\ + is Zebra shutting down?" + ) + } + } + } }