From 7010a068233f0425725e69c08c1a3fb8e016471c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Sat, 3 Apr 2021 16:58:09 +0200 Subject: [PATCH] make a panic a error! and improve logging --- network/src/api.rs | 18 ++++++++++-------- network/src/participant.rs | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/network/src/api.rs b/network/src/api.rs index bd5e03cddc..1692e4b87c 100644 --- a/network/src/api.rs +++ b/network/src/api.rs @@ -476,9 +476,9 @@ impl Network { } trace!("Participants have shut down - next: Scheduler"); - shutdown_scheduler_s - .send(()) - .expect("Scheduler is closed, but nobody other should be able to close it"); + if let Err(()) = shutdown_scheduler_s.send(()) { + error!("Scheduler is closed, but nobody other should be able to close it") + }; if let Ok(return_s) = return_s { if return_s.send(()).is_err() { warn!("Network::drop stoped after a timeout and didn't wait for our shutdown"); @@ -1041,7 +1041,7 @@ impl core::cmp::PartialEq for Participant { } } -fn actively_wait(mut finished_receiver: oneshot::Receiver, f: F) +fn actively_wait(name: &'static str, mut finished_receiver: oneshot::Receiver, f: F) where F: FnOnce(T) + Send + 'static, T: Send + 'static, @@ -1055,7 +1055,7 @@ where handle.spawn(async move { match finished_receiver.await { Ok(data) => f(data), - Err(e) => panic!("{}: {}", CHANNEL_ERR, e), + Err(e) => panic!("{}{}: {}", name, CHANNEL_ERR, e), } }); } else { @@ -1067,7 +1067,7 @@ where f(data); break; }, - Err(TryRecvError::Closed) => panic!("{}", CHANNEL_ERR), + Err(TryRecvError::Closed) => panic!("{}{}", name, CHANNEL_ERR), Err(TryRecvError::Empty) => { trace!("activly sleeping"); cnt += 1; @@ -1094,7 +1094,9 @@ impl Drop for Network { .send(finished_sender) { Err(e) => warn!(?e, "Runtime seems to be dropped already"), - Ok(()) => actively_wait(finished_receiver, |()| info!("Network dropped gracefully")), + Ok(()) => actively_wait("network", finished_receiver, |()| { + info!("Network dropped gracefully") + }), }; } } @@ -1123,7 +1125,7 @@ impl Drop for Participant { { Err(e) => warn!(?e, SCHEDULER_ERR), Ok(()) => { - actively_wait(finished_receiver, |d| match d { + actively_wait("participant", finished_receiver, |d| match d { Ok(()) => info!("Participant dropped gracefully"), Err(e) => error!(?e, SHUTDOWN_ERR), }); diff --git a/network/src/participant.rs b/network/src/participant.rs index bc38a97b59..66668ca898 100644 --- a/network/src/participant.rs +++ b/network/src/participant.rs @@ -199,7 +199,7 @@ impl BParticipant { } // check for tcp if network_protocol::TcpSendProtocol::::supported_promises() - == promises + .contains(promises) { for (cid, p) in all.data.iter() { if matches!(p, SendProtocols::Tcp(_)) {