From 68d326c817d4674ed9b6be45622bb208bf9c3214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Wed, 14 Apr 2021 16:17:06 +0200 Subject: [PATCH] revert Client drop to be correct again and also stop network properly, reduce timeout to 10s --- client/src/lib.rs | 20 ++++++++++++-------- network/src/api.rs | 6 +++--- network/src/participant.rs | 4 +++- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index df53d4d46e..0fa74ad641 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -168,7 +168,7 @@ pub struct Client { // The pending trade the client is involved in, and it's id pending_trade: Option<(TradeId, PendingTrade, Option)>, - _network: Network, + network: Option, participant: Option, general_stream: Stream, ping_stream: Stream, @@ -676,7 +676,7 @@ impl Client { pending_invites: HashSet::new(), pending_trade: None, - _network: network, + network: Some(network), participant: Some(participant), general_stream: stream, ping_stream, @@ -2421,12 +2421,16 @@ impl Drop for Client { trace!("no disconnect msg necessary as client wasn't registered") } - self.runtime.spawn( - self.participant - .take() - .expect("Only set to None in Drop") - .disconnect(), - ); + tokio::task::block_in_place(|| { + if let Err(e) = self + .runtime + .block_on(self.participant.take().unwrap().disconnect()) + { + warn!(?e, "error when disconnecting, couldn't send all data"); + } + }); + //explicitly drop the network here while the runtime is still existing + drop(self.network.take()); } } diff --git a/network/src/api.rs b/network/src/api.rs index 4dcb919e1f..d4b282eac3 100644 --- a/network/src/api.rs +++ b/network/src/api.rs @@ -471,7 +471,7 @@ impl Network { let (finished_sender, finished_receiver) = oneshot::channel(); finished_receiver_list.push((remote_pid, finished_receiver)); a2s_disconnect_s - .send((remote_pid, (Duration::from_secs(120), finished_sender))) + .send((remote_pid, (Duration::from_secs(10), finished_sender))) .expect("Scheduler is closed, but nobody other should be able to close it"); }, None => trace!(?remote_pid, "Participant already disconnected gracefully"), @@ -1087,7 +1087,7 @@ where Err(TryRecvError::Empty) => { trace!("activly sleeping"); cnt += 1; - if cnt > 120 { + if cnt > 10 { error!("Timeout waiting for shutdown, dropping"); break; } @@ -1137,7 +1137,7 @@ impl Drop for Participant { debug!("Disconnect from Scheduler"); let (finished_sender, finished_receiver) = oneshot::channel(); match a2s_disconnect_s - .send((self.remote_pid, (Duration::from_secs(120), finished_sender))) + .send((self.remote_pid, (Duration::from_secs(10), finished_sender))) { Err(e) => warn!(?e, SCHEDULER_ERR), Ok(()) => { diff --git a/network/src/participant.rs b/network/src/participant.rs index 5ce2384410..c4a6101692 100644 --- a/network/src/participant.rs +++ b/network/src/participant.rs @@ -681,7 +681,9 @@ impl BParticipant { trace!("wait again"); wait_for_manager().await; - sender.send(Ok(())).unwrap(); + if sender.send(Ok(())).is_err() { + trace!("couldn't notify sender that participant is dropped"); + } #[cfg(feature = "metrics")] self.metrics.participants_disconnected_total.inc();