From a072d44a0d21274b9b3d66e3d0856a94c8770823 Mon Sep 17 00:00:00 2001 From: Boog900 Date: Wed, 25 Sep 2024 20:56:57 +0100 Subject: [PATCH] P2P: fix connection disconnect on `Client` drop (#298) fix connection disconnect on `Client` drop --- p2p/p2p-core/src/client/timeout_monitor.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/p2p/p2p-core/src/client/timeout_monitor.rs b/p2p/p2p-core/src/client/timeout_monitor.rs index 6dbb4a2..b736966 100644 --- a/p2p/p2p-core/src/client/timeout_monitor.rs +++ b/p2p/p2p-core/src/client/timeout_monitor.rs @@ -45,6 +45,9 @@ where CSync: CoreSyncSvc, PSync: PeerSyncSvc, { + let connection_tx_weak = connection_tx.downgrade(); + drop(connection_tx); + // Instead of tracking the time from last message from the peer and sending a timed sync if this value is too high, // we just send a timed sync every [TIMEOUT_INTERVAL] seconds. let mut interval = interval(TIMEOUT_INTERVAL); @@ -59,10 +62,10 @@ where tracing::trace!("timeout monitor tick."); - if connection_tx.is_closed() { + let Some(connection_tx) = connection_tx_weak.upgrade() else { tracing::debug!("Closing timeout monitor, connection disconnected."); return Ok(()); - } + }; let Ok(permit) = Arc::clone(&semaphore).try_acquire_owned() else { // If we can't get a permit the connection is currently waiting for a response, so no need to